Just starting out with core graphics. Playing with a simple button and label. I want this label to rotate 180 degrees on each click of the button. It only animates on the first click (the console does write "DONE" on each click, however)
- (IBAction)btnTest:(id)sender
{
[UIView animateWithDuration:1 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
lblTest.layer.transform = CATransform3DMakeRotation(M_PI,0.0,1.0,0.0);
}completion:^(BOOL finished) {
if(finished)
NSLog(@"DONE");
}];
}
The reason its not working is because on the first button press, the views rotation is set to 180 deg. On the second button press you set the rotation to 180 deg again but since that is the same as the current value of the rotation, nothing happens. What you really want to be doing is setting the rotation to 180 deg + the current rotation. You can achieve this by rotating the current transform by 180 deg with the following change.