【问题标题】:iOS - [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)] called too sooniOS - [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)] 调用太快了
【发布时间】:2013-11-20 12:37:48
【问题描述】:

我有一个带有

UIView 动画
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)] 

由于某种原因,animationDidStop:finished:context: 在动画结束之前被调用。 有任何想法吗? (在iOS7模拟器上测试)

代码:

-(void)checkForAndRemoveTable {

//The animation should fade to 0 then remove itself from it's superview at the end.

if (tableViewController.view.superview != nil) {

    [UIView beginAnimations:@"dismissTable" context:NULL];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
    tableViewController.view.alpha = 0;
    [UIView commitAnimations];

}


}


-(void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {

if ([animationID isEqualToString:@"dismissTable"]) {

     [tableViewController.view removeFromSuperview];
}


}

【问题讨论】:

    标签: ios iphone ipad animation uiview


    【解决方案1】:

    尝试使用基于块的动画。毕竟,Apple 从 iOS 4 开始就建议这样做。

    if (tableViewController.view.superview != nil) {
        [UIView animateWithDuration:0.5 delay:0.0 options:kNilOptions animations:^{
            tableViewController.view.alpha = 0;
        } completion:^(BOOL finished) {
            [tableViewController.view removeFromSuperview];
        }];
    }
    

    或者,这种行为也可能是由于对函数的滥用造成的。例如,如果发生快速连续多次调用动画函数的事件,则可能导致动画回调的计时似乎关闭。 (见下方评论)

    【讨论】:

    • 我用这个的时候同样的问题,但是我找到了原因!似乎我错误地调用了包含我的动画的函数两次(来自另一个函数)。请使用“请参阅 cmets 以获取解决方案”来更新您的答案。谢谢。
    【解决方案2】:

    在 iOS 4 及更高版本中,使用基于块的动画方法。 (推荐)-> 苹果文档

    使用[UIView animateWithDuration:animations:completion:]方法

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-18
      • 1970-01-01
      • 2013-01-18
      • 2013-06-26
      相关资源
      最近更新 更多