I’m trying to perform a simple animation using Cocoa. One button causes an image to flip over its y-axis when pressed, and then flip back when pressed again. The other button should cause the window to flip over its x-axis and back the same way. The image’s code works, whereas the window will flip vertically the first press, but will not flip back with the second.
Image on y-axis
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[pic.layer setValue:[NSNumber numberWithInt:3.14159] forKeyPath:@"transform.rotation.y"];
[UIView commitAnimations];
Window on x-axis
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[window.layer setValue:[NSNumber numberWithInt:3.14159] forKeyPath:@"transform.rotation.x"];
[UIView commitAnimations];
I’m having trouble finding the problem since the codes are nearly identical. Help would be appreciated, thanks.
I managed to get the code working with a slightly different format.
From what I can tell, whenever it got the rotate command, it only considered the window in its original state. Meaning that each new command to flip, it saw that it was already in the position requested, and did nothing. Once I realized that, I just had to give it the command to return it to normal. It’s still a mystery to me why the code in my question worked for y-axis and not x though.