我正在對圖像執行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]; – firewall
這不是一個很好的方法來實現這一點。使用performSelector:withObject:afterDelay:是一個破解。查看關於animateWithDuration的答案:動畫:completion :. –
...和'CGAffineTransformRotate',您可以使用它來旋轉視圖的'transform'屬性。 – CouchDeveloper