我有一个带有
的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/