I want to do a fairly simple rotation of a UIImageView. Basically I have an image of a wheel in a perfectly square image and I want to rotate it under animation.
So I tried this:
- (void)testButtonPressed:(id)sender {
NSLog(@"Test button pressed");
CGAffineTransform transform = CGAffineTransformMakeRotation(1.0);
[UIView animateWithDuration:10.0 delay:0 options:UIViewAnimationOptionCurveLinear
animations:^{
dial.transform = transform; // "dial" is a UIImageView
}
completion: ^(BOOL finished){
}];
}
What happens is that, when the animation begins the image (that's about 300 square) immediately jumps up 50-100 pixels and is "squeezed" into a narrow oval. After that, the animation proceeds just fine.
I tried using beginAnimation
instead and got the same behavior.
I understand that I don't understand the stuff about the rotation origin (the docs talk in circles), but the squeezing seems odd, and the fact that it all occurs at once (vs being animated) is strange.
Any ideas?
(This is running on the iPhone 6.0 simulator from Xcode 4.5.1. Is is possibly just a simulator thing?)
Update: I got a chance to work on it a little more (I do it in-between "real" work). I created a new XIB that never had autolayout and the wheel was "normal" but the background was vertically compressed.
Then a bit of inspiration. I noticed that the image views were marked "autoresize" in the NLog dumps. Didn't see a way to turn that off from IB, but did see that you can turn off "Autoresize Subviews" on the main view. Did that and it behaved perfectly!
I'm thinking that some of the new features introduced for autolayout are the culprit here. Don't know, though, if I've found all the magical settings yet.
But... Still have the problem that the "transparent" parts of my images are black on the iPad, even after turning off "Opaque" on everything.
Update: I've finally figured out that my images were in JPG 24 bit mode rather than 32 bit mode. This works on the simulator -- pure black is interpreted as transparent. But it doesn't work on the iPad. Using 32 bit images fixes that and (with "autoresize subviews turned off to eliminate the odd distortions/translations) everything is fine except ... rotations > 180 degrees animate backwards. The animation is being "smart" and taking the "shortest path".
I suppose I'll simply have to break the animation into two steps.