What does installing CALayer bounds.origin do?

The CALayer API uses "position" to set the position of a layer.

With its own testing, setting bounds.origin does nothing. Did I miss something?

+4
source share
2 answers

The bounds.origin element determines where the origin of the coordinate system of the layer is, relative to the borders of the layer in its super layer. Changing it has two visible effects:

  • The position of the sublayers of the layer. For example, when you scroll through a UIScrollView , the scroll does not change its frame subframes. He just changes his bounds.origin . I suggest setting up a toy application with a scroll list and doing NSLog("scroll view bounds = %@", NSStringFromCGRect(scrollView.bounds)); using a timer or some other trigger to understand what is happening.

  • The origin of the graphical context coordinate system in drawInContext: Most often you will see this effect in the form of drawRect: Your CGContext inside drawRect: will be translated as self.bounds.origin .

You may find it helpful to read “Viewing Geometry and Coordinate Systems” in the iOS Programming Guide and “Layer Objects Define Their Own Geometry” in the main animation programming guide , although in fact none of them have a good discussion of the origin of boundaries.

+4
source

Changing the borders of the borders changes the position and size of the content in the coordinate system of the layer itself. Changing the frame (or position) changes the position of the layer in the coordinate system of its super layer. Usually you want to change the frame, not the borders.

+1
source

Source: https://habr.com/ru/post/1488155/


All Articles