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 Answers
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.
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.

- 13,391
- 3
- 64
- 104
-
If value of frame is undefined and therefore should be ignored, then how does the system decide where to draw the layer. In fact, what confuse me is that my layer is always larger than the layer's bounds.size – keywind Jun 22 '12 at 05:45
-
1it uses the center property, "In that case, you can reposition the view using the center property and adjust the size using the bounds property instead." its all in the documentation. And it makes perfect sense, when you rotate something the "square" containing it must grow therefore the bounds define the size of the inner square and the frame of the containing square. – Pochi Jun 22 '12 at 05:52
-
Yeah, I understand. Because I scale 2x, so the bounds is also display 2x. for example, size(100,100) will display as size(200,200) – keywind Jun 22 '12 at 12:26
-
1You don't have to ignore the frame when a layer is transformed. In fact, the frame is just going to represent the smallest rect that fully contains the transformed layer, which is useful. The bounds remains unchanged regardless of transform. So they're just two different representation of coordinate space, depending on what you're interested in. – CIFilter Jan 20 '17 at 07:49