2

我正在对图像执行动画,并将其旋转 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];

}
4

1 回答 1

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];
    }];
于 2013-07-16T21:06:59.887 回答