我正在我将图像旋转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];
}
答案 0 :(得分:5)
使用UIView的animateWithDuration:animations:completion:方法。在完成块中调用performSegueWithIdentifier:sender:。例如:
[UIView animateWithDuration:1.5
animations:^{
// put your animation code here, eg:
CGAffineTransform transform = CGAffineTransformMakeRotation(M_PI_2);
self.imageView.transform = transform;
}
completion:^{
[self performSegueWithIdentifier: @"ToGalleryVCSegue" sender: self];
}];