Resetting the origin of a transformed UIView descends into craziness

喜夏-厌秋 提交于 2019-12-05 05:42:40

问题


I rotate/scale a UIVIew using [UIView transform:] and this works well. However, as soon as I change the view's frame origin the contents of the view begins to scale 'weirdly' even though I am not performing any further CGAffineTransforms.

Why does this occur? How can I prevent it?

Update 1:

The docs suggest that the frame is invalid after a transform. Can I move the view via it's 'center' property instead?

Update 2:

Setting the views center did allow me to translate the view successfully after a transform had been applied.


回答1:


Can I move the view via it's 'center' property instead?

The documentation defines the center property as:

The center of the frame.

and says:

The center is specified within the coordinate system of its superview.

I'd try it.




回答2:


From the UIView docs:

transform:

Warning: If this property is not the identity transform, the value of the frame property is undefined and therefore should be ignored.

The center property is just a convenience method that really resets the frame's origin.

Edit: appended to answer comment:

If you're using the transform property and want to reposition your view, you have to concatenate the translation to your transform using:

view.transform = CGAffineTransformTranslate(view.transform, tx, tx);


来源:https://stackoverflow.com/questions/1047947/resetting-the-origin-of-a-transformed-uiview-descends-into-craziness

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