我正在尝试以与使用 CATransition 淡入淡出推送视图控制器相同的方法停止 UIActivityIndicatorView 上的动画。
无论我设置持续时间多长,UIActivityIndicatorView 都不会停止动画,然后淡入下一个视图控制器,而是在整个淡入淡出过程中继续设置动画。
有什么想法可以让旋转停止,然后以相同的方法推动/淡入淡出吗?
- (void)pushView:(NSNotification *)notification {
[self.activityIndicator stopAnimating];
NextViewController* nextViewController = [[NextViewController alloc] init];
CATransition *transition = [CATransition animation];
transition.duration = 1.5f;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionFade;
[self.navigationController.view.layer addAnimation:transition forKey:nil];
[self.navigationController pushViewController:nextViewController animated:NO];
}
编辑 1
stopAnimating
与大卫的回答一样,如果我使用dispatch_after
并延迟了几分之一秒,我就能成功。有没有更好的方法来做到这一点?:
- (void)pushView:(NSNotification *)notification {
[self.activityIndicator stopAnimating];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.0001 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void){
NextViewController* nextViewController = [[NextViewController alloc] init];
CATransition *transition = [CATransition animation];
transition.duration = 1.5f;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionFade;
[self.navigationController.view.layer addAnimation:transition forKey:nil];
[self.navigationController pushViewController:nextViewController animated:NO];
});
}