gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 10:51:46 27 4
gpt4 key购买 nike

我有一个带有

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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com