【发布时间】:2013-07-16 20:57:17
【问题描述】:
我正在对图像执行动画,并将其旋转 180 度。
然后我插入了一个代码来切换到另一个视图。
但是,应用会在动画结束前切换视图。
如何等待动画完成才能切换视图?
这是我的代码:
- (IBAction)buttonPressed:(id)sender
{
CABasicAnimation *imageRotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
imageRotation.fromValue = [NSNumber numberWithFloat:0];
imageRotation.toValue = [NSNumber numberWithFloat:((180*M_PI)/ 180)];
imageRotation.duration = 1.5;
imageRotation.repeatCount = 1;
imageRotation.removedOnCompletion = NO;
imageRotation.autoreverses=NO;
imageRotation.fillMode = kCAFillModeForwards;
[_image.layer addAnimation:imageRotation forKey:@"imageRotation"];
// Switching Views
[self performSegueWithIdentifier: @"ToGalleryVCSegue" sender: self];
}
【问题讨论】:
-
我从另一篇文章中找到了答案。它使用以下内容:[self performSelector:@selector(metohodToPushView) withObject:nil afterDelay:0.8];
-
这不是实现这一目标的好方法。使用 performSelector:withObject:afterDelay: 是一种技巧。查看有关 animateWithDuration:animations:completion: 的答案。
-
... 和
CGAffineTransformRotate可用于旋转视图的transform属性。
标签: ios animation switch-statement wait