The problem of understanding CALayer Geometry. Help is needed

I try to understand the Kaiser geometry, but I have an understanding of this

  • Position (this is clear to me)

  • Borders (Apple docs says) The bounds property is a CGRect that provides layer size (bounds.size) and origin (bounds.origin).

The origin of the borders is used as the source of the graphics context when you override the methods of drawing a layer.

I did not think about ratings.

  • Frame (spoken in Apple docs).

Layers have an implicit frame, which is a function of position, bounds, anchorPoint, and transform. Setting a new frame rectangle changes the properties of the layer and the properties of the borders properly, but the frame itself is not saved. When a new frame, a rectangle indicates that the origin is unperturbed, and the border size is set to the frame size. The position of the layer is set in the desired position relative to the anchor point. When you get the value of a frame property, it is calculated relative to the position, borders, and anchorPoint properties.

but it is much more complicated and different from this lecture slide at Stanford University 19

  • AnchorPoint This is, after all, a game with borders ... making your head spin.

Help is needed.

Thanks, Regards.

+4
source share
1 answer

Each view has its own coordinate system.

A coordinate system of any kind has a coordinate origin (0,0). Thus, the boundaries of any representation are the "boundaries" of this coordinate system, i.e. (0, 0, width, height).

A position of any kind is calculated based on the coordinate system of the parent view or superview . This is a frame of any kind, which therefore will be (x, y, width, height), where x and y represent the left and top or the position of the upper left corner in the original coordinate system.

The ios documentation explains this with this image

This should explain things much better

And for the latter, since AnchorPoint is โ€œinsideโ€ the view, it is represented in the coordinate system of the view and therefore must use borders, as well as the center property.

This is also true for CALayer, where the boundaries of the layers are defined in their own coordinate system, and their frames are determined by their supervisors. There are many differences, some of them are direct, for example, layers have much deeper control, so you can set zordering and have a reference point for working with transformations, etc. Some of them are subtle, for example, for example, the frame CALayer property is not animated (i.e., its change in the animation block is not affected).

And I suggest you try smaller programs to understand the differences in addition to just trying to extract everything from a book or two, or even in this case even SO.

+3
source

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


All Articles