Animate rotation and location of view at same time
What is the best way to rotate a view and move its location at the same time?
I want this view to rotate 1 full revolution while sliding to the left,
then rotate the other direction while sliding back to its original
position. I got the first part of this working (rotate while sliding to
left), but when I try to rotate while sliding back to the right, the view
jumps back to its original spot without animating.
What am I doing wrong?
// step 1 (this works)
[UIView animateWithDuration:0.3f animations:^{
self.number.transform =
CGAffineTransformMakeRotation(DegreesToRadians(180));
self.number.transform = CGAffineTransformMakeTranslation(-160, 0);
self.number.center = CGPointMake(self.number.center.x - 160,
self.number.center.y);
} completion:nil];
// step 2 (this doesn't work)
[UIView animateWithDuration:0.2f animations:^{
self.number.transform =
CGAffineTransformMakeRotation(DegreesToRadians(180));
self.number.transform = CGAffineTransformMakeTranslation(160, 0);
self.number.center = CGPointMake(self.number.center.x + 160,
self.number.center.y);
} completion:nil];
No comments:
Post a Comment