【问题标题】:Observer called function not animating观察者调用函数没有动画
【发布时间】:2020-01-01 19:42:15
【问题描述】:

我有一个功能

 -(void)setCurrentDuration:(double)currentTime
 {
     [self.slider setValue:currentTime animated:YES];
 }

在 UIPhilosophyViewCell 单元格中。

打电话

for (UIPhilosophyViewCell* cell in [self.customTableView visibleCells])
    {
        if ([cell isKindOfClass:[UIPhilosophyViewCell class]])
        {
            if ([TRIM(cell.dicData[@"id"]) isEqualToString:self.currentPlayingID])
            {
                [cell.audioProgressViewController setCurrentDuration:[self.audioPlayer currentTime]];
            }
        }
    }

动画滑块值更改,但从通知观察者的选择器调用的 setCurrentDuration 不会。关于可能是什么问题的任何建议?

将单元格添加到通知中心

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveTestNotification:) name:@"playingProgress" object:nil];

和选择器

- (void) receiveTestNotification:(NSNotification *) notification
{
    NSDictionary* data = notification.object;
    if (data == nil)
    {
        data = [NSDictionary dictionary];
    }

    if ([[notification name] isEqualToString:@"playingProgress"] && [TRIM(self.dicData[@"id"]) isEqualToString:TRIM(data[@"id"])])
    {
        [self setCurrentDuration:[(NSNumber*)TRIM(data[@"currentDuration"]) doubleValue]];
    }
    else
    {
        [self setCurrentDuration:0];
    }
}

TRIM 是获取非 nil 对象或字符串的函数

【问题讨论】:

  • 我认为这个问题与线程有关;即确保您在观察者的 UI 线程上进行更改。
  • 包裹后仍然没有动画 [self setCurrentDuration:[(NSNumber*)TRIM(data[@"currentDuration"]) doubleValue]];在 dispatch_async(dispatch_get_main_queue(), ^() {}

标签: ios objective-c animation nsnotificationcenter observers


【解决方案1】:

TableView 重新加载或更新可能会停止单元格的动画。

所以,试试改用[self.slider setValue:currentTime animated:NO];

如果 setValue 有效,则需要考虑动画实现。

【讨论】:

  • TableView 没有重新加载并且 [self.slider setValue:currentTime animated:NO];也没有动画,因为没有
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-11-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-11-02
相关资源
最近更新 更多