iOS concept: Frame,bound,center, Anchorpoint

Source: Internet
Author: User

frame: The coordinates of view in its Super view coordinate system

bound: The origin of the rect,rect used to define the view's own coordinate system and boundary represents the origin coordinates of the view's own coordinate system. As an example:

In general, the value of bound is (0,0,width,heigh), where 0, 0 indicates that the origin coordinates of the view's own coordinate system are (0,0)

But since the type is rect, I can also set bound (0,0), such as the bound value (10,10,width,height). This means that the coordinates of the point in the view's own coordinate system are (10,10). This has no effect on the view itself, but for the view's subview, their display position may have to subtract the value of the origin from the value of the frame. Look at the following code:

Class Layerviewcontroller:uiviewcontroller {    private var sublayer:calayer!;        Override Func Viewdidload () {        super.viewdidload () let        SubView = UIView ();        Subview.backgroundcolor = Uicolor.bluecolor ();        Subview.bounds = CGRect (x:50, y:50, width:50, height:50);        Subview.frame = CGRect (x:100, y:100, width:50, height:50);                Let Thirdview = UIView ();        Thirdview.backgroundcolor = Uicolor.redcolor ();        Thirdview.frame = CGRect (x:50, y:50, Width:10, height:10);        Subview.addsubview (Thirdview);        Self.view.addSubview (SubView);    }}

UI Rendering Effects:

Although the Thirdview frame is set to (50,50,50,50), the bound origin of the Subview is (50,50). So Thirdview is displayed in the upper-left corner of the subview.

Anchorpoint:

In fact, the attributes in the Calayer are not exposed in the view. So if we need to modify it we need to do this by modifying the Anchorpoint property of the view's associated layer. The anchorpoint is used to determine the point at which to make a reference point when doing the rotation, amplification, and other operations. His value is a relative to the bound value, within the bound, the value range is (0,0) ~ (max)

Center

Represents the position of the view's anchorpoint in the Super view's coordinate system.

Frame and bound can this view of the weight and height, that can be set differently? The answer is yes. In fact, frame is a virtual property whose value is computed by bound and center. The values of bound and center are also reset when the frame is assigned a value.

iOS concept: Frame,bound,center, Anchorpoint

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.