In-depth understanding of technology sharing-bounds

Source: Internet
Author: User

---restore content starts---

Make BY-LJW

Preface: The Beginner's knowledge of bounds is the origin of coordinates in the upper left corner of his own, and X/y is generally 0,0 . But after a deep understanding of bounds, we should re-recognize it. Here are some of the bounds's knowledge: bounds: X/y is generally (0,0) The default rectangle box and content is overlapping, so the default is (0,0) change a control bounds x/y on the control does not affect, the child control has an effect to modify the parent control's bounds as (20,20) then the children control will move up relative to the parent control (20,20) knowledge of a control:At least it consists of two large chunks: 1. Rectangle: The display position and size of the control 2. Content: Something inside a control, such as its child control bounds: The position and dimensions of the rectangle are calculated by using the upper-left corner of the control's own content as the origin of the coordinates, so the bounds is the location and the size. Frame: The position and size of the rectangle position and dimension control itself is determined by the frame, with the upper-left corner of the parent control being the coordinate origin, so the position of the parent control is not changed to the position of the content because the bounds is modified. The position of the child control changes with the position of the content and at this time, The child control is offset, but the child control's frame is not changed because the child control's frame is the origin of the coordinates at the upper-left corner of the parent control's content, the content is offset (30,30), but the child control is also offset (30,30), relative to the content or (0,0)
-(void) Touchesbegan: (Nsset<uitouch *> *) touches withevent: (Uievent *) event {    cgrect bounds =  Self.redView.bounds;    Bounds.origin = Cgpointmake (+);    Self.redView.bounds = bounds;        NSLog (@ "%@", Nsstringfromcgrect (Self.s.frame));}    
Practical Application:ScrollView: Drag down, then the child control of the bounds Y is negative, upward drag, the content goes up, the Y value will be more and more left to drag, content to the left, then relative to the upper left corner of the content is the origin, X is positive, more and more large At this point, the size of the bounds is constant, or the width of the rectangle box is high effects of Bounds on Contentoffset:ScrollView up and down to drag, Contentoffset will also change, and change the value of bounds is the same, representing the content of the offset
Scrollview.contentinset = Uiedgeinsetsmake (64, 0, 0, 0);

effects of Bounds on Contentinset:Set the padding to 64, then the content X will make-64, because the content is shifted downward. So modify the padding, you may permanently modify the value of the bounds, drag down the control and the top will always retain 64 spacing Practical Application:TableView the cell to set an additional offset
Self.tableView.contentInset = uiedgeinsetsmake (0, 0, 0);
ScrollView the same; Verify:
-(void) TableView: (UITableView *) TableView Didselectrowatindexpath: (Nsindexpath *) indexpath{    NSLog (@ "%@") , Nsstringfromcgpoint (TableView.bounds.origin));} 

Print the results:

Therefore, the origin of bounds is the same as the value of Contentoffset, and the modification of Contentinset will affect both.

When a controller ScrollView a navigation controller, then the scrollview inside the child control will be shifted downward 64 that is, in the navigation controller environment, the system will automatically adjust the distance from the top 64 of the padding, then the bounds:-64, offset is 64 What caused it? Hide the navigation bar, then the distance from the top offset to 20, because there are 20 of the status bar. This is done to prevent the full-screen use of scrollview when blocking the display of the control, the most obvious is the TableView cell but there are multiple scrollview cases , only one conclusion is adjusted: Which control is added first, then who is adjusted. But many things are not available (typically used in tableview cells). Cancel this effect: 1. Setting properties
Self.automaticallyadjustsscrollviewinsets = NO;

2. Set the corresponding offset offset

Self.scrollView.contentInset = Uiedgeinsetsmake (-64, 0, 0, 0);

Official Document Description

Effects of Tabbarcontroller on Contentinset:

If the ScrollView quilt Navigationcontroller and Tabbarcontroller, scroll to the top, the system will automatically move down 64, scroll to the bottom, increase by 49. Make sure the contents are visible.

After the iOS7, the Apple made this effect and was able to penetrate. But only Tabbarcontroller will not have automatic adjustment.

Printing results:

Summary:A re-understanding of frame and bounds
    • Frame
      • The 父控件 内容 控件自己 矩形框 position and size calculated by the upper-left corner of the coordinate origin.
    • Bounds
      • The 控件自己 内容 控件自己 矩形框 position and size calculated by the upper-left corner of the coordinate origin.
    • Summarized
      • Frame.size = = Bounds.size
      • ScrollView.bounds.origin = = Scrollview.contentoffset
the difference between bounds and frameUnderstanding of rectangular boxes and content
    • Rectangle box
      • control's own display position and size
    • Content
      • Something inside the control, such as its child controls

---restore content ends---

In-depth understanding of technology sharing-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.