When to use snapping and when to use a frame

I found out that

The borders of a UIView are a rectangle expressed as a location (x, y) and size (width, height) relative to its own coordinate system (0,0).

The UIView frame is a rectangle expressed as the location (x, y) and size (width, height) relative to the supervision in which it is contained.

But my doubt is in which scenario I will have borders to be used. We will not use frames in

all cases? Do I need to use binding?

+4
source share
1 answer

From View Programming Guide :

  • The frame property contains the frame rectangle, which determines the size and location of the view in its supervisor coordinate system.
  • The bounds property contains a border rectangle that determines the size of the view (and its content source) in its own local coordinate system of the views.

Frame:

You use the center and frame properties mainly to control the geometry of the current view. For example, you use these properties when building a hierarchy of views or changing the position or size of a view at run time. If you only change the position of the view (and not its size), the center property is the preferred way to do this. The value in the center property is always true, even if scaling or rotation factors have been added to the transformation of representations. The same is not true for the value in the frame property, which is considered invalid if the transformation of the representations is not equal to unity transformation.

Bounds:

You use the bounds property mainly while drawing . Borders A rectangle is expressed in its own local coordinate system. by default, this rectangle is (0, 0), and its size corresponds to the size of the frame rectangle. Everything you draw inside this rectangle is part of the visible content. If you change the source of the border rectangle, everything you draw inside the new rectangle becomes part of the visible content.

So, you perform the following actions with the frame :

  • view size
  • moving / moving.

The situation when you should use borders :

  • when you draw constrained views inside, for example. in drawRect: method of UIView .
  • adding subViews to the borders of parent views
+10
source

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


All Articles