UIView动画全圆旋转与UIViewAnimationOptionCurveEaseInOut反转

时间:2013-09-17 12:02:54

标签: ios animation uiview

           [UIView animateWithDuration:3 delay:0 options:( UIViewAnimationOptionCurveEaseInOut |
                                                       UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat |
                                                       UIViewAnimationOptionAllowUserInteraction) animations:^{
            self.animatedImageView.transform = CGAffineTransformRotate(self.animatedImageView.transform, M_PI);
        } completion:^(BOOL finished){}];

这个动画如何能够在加速和减速的同时进行整圈旋转。如果我使用2 * M_PI,则动画不会移动。

2 个答案:

答案 0 :(得分:11)

我认为这应该适合你:

- (IBAction)rotate:(UIButton *)sender {

    CABasicAnimation *rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    rotationAnimation.toValue = @(M_PI * 2.0);
    rotationAnimation.duration = 1;
    rotationAnimation.autoreverses = YES;
    rotationAnimation.repeatCount = HUGE_VALF;
    rotationAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    [self.iv.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
}

答案 1 :(得分:5)

 [UIView animateWithDuration:3 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
            self.animatedImageView.transform = CGAffineTransformRotate(self.animatedImageView.transform, M_PI);
        } completion:^(BOOL finished){

        [UIView animateWithDuration:3 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
        self.animatedImageView.transform = CGAffineTransformRotate(self.animatedImageView.transform, (2*M_PI)-0.001); //  -0.001 will do the right way
    } completion:^(BOOL finished){}];


}];