iOS 360度无限旋转动画

2018/07/06 iOS 动画

旋转动画

-(void)rotateImageView {
    [UIView transitionFromView:self.calendar toView:self.stepTopView duration:0.8f options:UIViewAnimationOptionTransitionFlipFromRight completion:^(BOOL finished) {
        [self rotateImageView];
    }];
}

CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
//默认是顺时针效果,若将fromValue和toValue的值互换,则为逆时针效果
animation.fromValue = [NSNumber numberWithFloat:0.f];
animation.toValue = [NSNumber numberWithFloat: M_PI *2];
animation.duration = 4;
animation.autoreverses = NO;
animation.removedOnCompletion = NO; // 关闭进入后台停止动画
animation.fillMode = kCAFillModeForwards;
animation.repeatCount = MAXFLOAT; //如果这里想设置成一直自旋转,可以设置为MAXFLOAT,否则设置具体的数值则代表执行多少次
[self.circleImgView.layer addAnimation:animation forKey:nil];

Search

    Table of Contents