I want to rotate an UIImageView
, it works in iOS8 but not in iOS7. Here's the code, I'm doing,
- (void)awakeFromNib {
[self createAnimation];
}
- (void)animationStart {
[self.animationImageView.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
}
- (void)animationStop {
[self.animationImageView.layer removeAnimationForKey:@"rotationAnimation"];
}
- (void)createAnimation {
rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
rotationAnimation.toValue = [NSNumber numberWithFloat: -M_PI * 2.0 ];
rotationAnimation.duration = 0.7;
rotationAnimation.cumulative = YES;
rotationAnimation.repeatCount = CGFLOAT_MAX;
}
use this code to image rotate,
- (void)startSpinImage
{
if ([_img.layer animationForKey:@"SpinAnimation"] == nil)
{
CABasicAnimation* animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
animation.fromValue = [NSNumber numberWithFloat:0.0f];
animation.toValue = [NSNumber numberWithFloat: 2*M_PI];
animation.duration = 10.0f;
animation.repeatCount = INFINITY;
[_img.layer addAnimation:animation forKey:@"SpinAnimation"];
}
}
- (void)stopSpinImage
{
[_img.layer removeAnimationForKey:@"SpinAnimation"];
}
Try using
[animationImageView startAnimating];
[animationImageView stopAnimating];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.