why CGAffineTransformRotate in autolayout will shift the animated view?

房东的猫 提交于 2019-12-07 06:30:17

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!