iOS view frame vs. bounds

Source: Internet
Author: User

Child view Actual position = Parent View actual location-parent view bounds coordinates + child view frame coordinates

First, bounds

Affects only the position of the child view relative to the screen, and does not affect its relative screen position when modified

Bounds coordinates: Your own defined coordinate system, Setbound indicates the coordinates of the upper-left corner of this view in the coordinate system,

Default value (0,0)

Second, frame

The modification changed its position in the parent view coordinate system (bounds coordinate system), its own position and

The child view location will be changed.

Frame coordinates: The coordinates of the upper-left corner of the child view in the parent view coordinate system (bounds coordinate system), default value (0,0)

Third, the chart explanation

See the following code first you must understand something:

-(CGRect) frame{
return CGRectMake (self.frame.origin.x,self.frame.origin.y,self.frame.size.width,self.frame.size.height);
}
-(CGRect) bounds{
return CGRectMake (0,0,self.frame.size.width,self.frame.size.height);
}


It is clear that the origin of a view's bounds is always (0,0) (The coordinate system of the view itself, which is always 0, 0, unless it is considered setbounds), and the view's frame origin is arbitrary (relative to the coordinate position in the parent view).

Look at sketch and you'll see.

Frame: The position and size of the view in the parent view coordinate system. (reference point is, Father's coordinate system)
Bounds: The position and size of the view in the local coordinate (own) system. (The reference point is that the local coordinate system is equivalent to VIEWB's own coordinate system, starting at 0, 0 points)
Center: The position and size of the view's central point in the parent view coordinate system. (reference point is, Father's coordinate system)

Bounds This property is referenced by this local coordinate system. In fact, the key to the local coordinate system is to know where its origin (0,0) is. (This position is also relative to the upper view of the local coordinate system, of course, the top layer of view is Self.window.) Its local coordinate system origin is the upper left corner of the screen.

By modifying the view's Bounds property, you can modify the local coordinate system's origin location, which affects the coordinates of all the view's child view.

iOS view frame vs. bounds

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.