CALayer frame.size not equal to bounds.size

☆樱花仙子☆ 提交于 2019-12-12 08:15:25

问题


I happened to something strange to me on CALayer.And finally found the CALayer's frame.size not equal to its bounds.size, which I couldn't understand.I know frame is in the super's coordinate system and bounds is its own coordinate,and the usual case is frame.origin is not equal to bounds.origin but frame.size is equal to bounds.size.


回答1:


That is because you applied a transform, as apple says on the documentation for the frame property.

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

...

Changes to this property can be animated. However, if the transform property contains a non-identity transform, the value of the frame property is undefined and should not be modified. In that case, you can reposition the view using the center property and adjust the size using the bounds property instead.

http://developer.apple.com/library/ios/#documentation/uikit/reference/UIView_Class/UIView/UIView.html

If you do not have a transform applied then the origin might be different but the size should remain the same as adjusting one re adjusts the other.

The size of the bounds rectangle is coupled to the size of the frame rectangle, so that changes to one affect the other.



来源:https://stackoverflow.com/questions/11149510/calayer-frame-size-not-equal-to-bounds-size

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