The difference between bounds and frame in UIView

Source: Internet
Author: User

iOS development of children's shoes are almost always used UIView, then his bounds and frame two properties will not be unfamiliar, then these two what is the difference between the material?

See the following code first you must understand something:

-(CGRect) frame{
Returncgrectmake (Self.frame.origin.x,self.frame.origin.y,self.frame.size.width,self.frame.size.height);
}
-(CGRect) bounds{
Returncgrectmake (0,0,self.frame.size.width,self.frame.size.height);
}
Obviously, the origin of the bounds is the (0,0) point, and the frame's origin is arbitrary.


Take a look at the picture and you'll know better.




Basic concepts:

Frame: The position and size of the view in the parent view coordinate system. (The reference point is the father's coordinate system) bounds: The view's position and size in the local coordinate system. (reference point is, local coordinate system) Center: The position and size of the view's center point in the parent view coordinate system. (referring to electricity, the father's coordinate system) is actually only bounds and center two properties. Frame is for easy and intuitive extra properties. So modifying one may affect other properties. The document reads as follows: Although you can set the values of theseproperties independently, setting the value for one changes Theothers The following ways:when you set the Frame property, the sizeof the Bounds property was set to match the size of T Heframeproperty.      The Center property was also adjusted to match Thecenter point of the new frame.      When you set the center property, Theorigin of the frame changes accordingly. When you set the size of the boundsrectangle, the size of the frame rectangle changes to match.
The first two are obviously, the last bounds a little bit confusing. This is the way to go. Local coordinate system: each view has a local coordinate system. This coordinate system function is more important, such as the touch of the callback function in the Uitouch inside the > Coordinate values are reference to the local coordinate system coordinates. Of course bounds this attribute is also referred to this local coordinate system. In fact, the key of the local coordinate system is to know where its origin (0,0) is located (this position is relative to the upper view of the local coordinate system, of course, the top layer of view is the window its local coordinate system origin is the upper left corner of the screen). The local coordinate system's origin location can be modified by modifying the view's Bounds property.
Modify the bounds test result: Bounds (0,0,100,100)-and (0,0,200,200) Local coordinate system origin to the left up to 50 respectively. Center is unchanged, the effect is to follow the center zoom view Bounds (0,0,100,100)--(100,100,100,100) Local coordinate system origin to the left to 100 respectively. Center unchanged, no visual effects change (but local coordinate system origin has changed) conclusion:

The bounds property affects the origin of the local coordinate system. Need to be aware

The difference between bounds and frame in UIView

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.