问题
I want to rotate a imageView using the following code:
[UIView animateWithDuration:.25 animations:^{
self.imageView.transform = CGAffineTransformRotate(self.plusView.transform, M_PI_4);
}];
the wired thing is that: if I run this code without auto layout, every thing is fine. but when using autolayout, the image view shift a litter pixel before rotate, why?
回答1:
When using auto layout in Xcode 5, you need to add a constraint to fix the horizontal center and vertical center of the imageView in its container. If you are using storyboards, this can be easily done with the constraints options. You will also need to fix the width and height with constraints if you don't want the imageView auto-resized.


回答2:
I did not have the reputation to comment on chazzwozzer's answer (my account got reset with recent changes to Facebook login). That answer worked good for me.. by putting the control that was being transformed into a UIView that had different constraints on it. Then the control that was being transformed is set to Horizontal AND Vertical Center in that view.
FYI.. the shift on transform did NOT occur on later iOS 8.. only on iOS 7.1.
来源:https://stackoverflow.com/questions/13286640/why-cgaffinetransformrotate-in-autolayout-will-shift-the-animated-view