动画完成后执行的操作 [英] Perform an action after the animation has finished

查看:143
本文介绍了动画完成后执行的操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的图像上执行的动画,我旋转180度。

然后我就插入了一个code切换到另一个视图。

但是,应用程序是在动画结束前交换了意见。

我怎么能等待动画以便事后切换视图完成?

下面是我的code:

   - (IBAction为)按钮pressed:(ID)发送者
{
    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];    //切换视图
    [个体经营performSegueWithIdentifier:@ToGalleryVCSegue发件人:个体经营];}


解决方案

使用的UIView的animateWithDuration:动画:完成:方法。把你给performSegueWithIdentifier电话:发件人:在完成块。例如:

  [UIView的animateWithDuration:1.5
                 动画:^ {
        //把你的动画code在这里,例如:
        CGAffineTransform变换= CGAffineTransformMakeRotation(M_PI_2);
        self.imageView.transform =变换;
    }
                 完成:^ {
        [个体经营performSegueWithIdentifier:@ToGalleryVCSegue发件人:个体经营];
    }];

I'm performing an animation on an image where I rotate it 180 degrees.

Then I have inserted a code to switch to another view.

However, the app is switching views before the animation ends.

How can I wait for the animation to finish in order to switch view afterwards?

Here's my code:

- (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];

}

解决方案

Use UIView's animateWithDuration:animations:completion: method. Put your call to performSegueWithIdentifier:sender: in the completion block. eg:

[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];
    }];

这篇关于动画完成后执行的操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆