Reputation: 2405
I'm using this code to Rotate my image.
- (IBAction)spin:(id)sender {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:5.0];
[UIView setAnimationBeginsFromCurrentState:YES];
self.imgRad.transform = CGAffineTransformMakeRotation(arc4random() % 360 * M_PI / 180);
[UIView commitAnimations];
}
Now I have two problems.
first: If the random number is greater than 90, the image moves with its center closer to the right corner. And its in relation to the random number. So higher number = the image's position is closer to the right corner. How can I fix that? Do I have to set a new center of my UIImageView
every time its greater than 90?
second: If the number is for example 300, the image doesn't rotate 300 degrees, it just rotates 60 degrees the other way. How can i fix this problem?
Thanks a lot!
Upvotes: 0
Views: 750
Reputation: 647
CAAnimation
.NSNumber
.The code :
CABasicAnimation *rotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
rotation.fromValue = [NSNumber numberWithFloat:0];
rotation.toValue = [NSNumber numberWithFloat:(arc4random() % 360 * M_PI / 180)];
rotation.duration = 5.0f;
rotation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
rotation.fillMode = kCAFillModeForwards;
rotation.removedOnCompletion = NO;
[self.imgRad.layer addAnimation:rotation forKey:@"rotatationRandom"];
Upvotes: 2