iOS - [UIView setAnimationDidStopSelector :@selector(animationDidStop:finished:context:)] called too soon

标签 ios iphone ipad animation uiview

我有一个带有

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];
}


}

最佳答案

尝试使用基于 block 的动画。毕竟,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];
    }];
}

或者,此行为可能是由于滥用该功能所致。例如,如果发生快速连续多次调用动画函数的事件,则可能导致动画回调的计时出现偏差。 (见下面的评论)

关于iOS - [UIView setAnimationDidStopSelector :@selector(animationDidStop:finished:context:)] called too soon,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20096198/

相关文章:

iphone - 将导航栏添加到 detailview 和 tableview

ios - 取消交互式 UINavigationController 弹出手势不会调用 UINavigationControllerDelegate 方法

ios - CPT ScatterPlot 连接点与跳过一些数据点

ios - 如何在 swift 中解析并存储 json 字典中的整数值?

ios - UIView背景太模糊

iphone - 在iphone编程中将自定义字体设置为默认字体

iphone - 在 AppDelegate 中使用自定义委托(delegate)

ios - swift : implementing a new item dialogue like 'add alarm' in clock app

ios - 如何从 App Store 中删除 iOS 应用程序

iphone - UIPinchGestureRecognizer 和 UIImageView 的问题