Spinning of a Gif image...
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIImageView* animatedImageView = [[UIImageView alloc] initWithFrame:CGRectMake(50, 100, 80, 80)];
animatedImageView.image = [UIImage imageNamed:@"you gif image.gif"];
[self.view addSubview: animatedImageView];
[self runSpinAnimationOnView:animatedImageView duration:5.0f rotations:0.5 repeat:2.0]; // make rotation as you want
}
- (void) runSpinAnimationOnView:(UIImageView*)view duration:(CGFloat)duration rotations:(CGFloat)rotations repeat:(float)repeat {
CABasicAnimation* rotationAnimation;
rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 /* full rotation*/ * rotations * duration ];
rotationAnimation.duration = duration;
rotationAnimation.cumulative = YES;
rotationAnimation.repeatCount = repeat ? HUGE_VALF : 0;
[view.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
}
No comments:
Post a Comment