iOS under Bound,center and frame

Source: Internet
Author: User

---restore content starts---

This article forwards to: http://www.xuebuyuan.com/1846606.html

When writing the program, it is found that the coordinates, the location of iOS is easy to mess up, especially in different coordinate systems, must be done to understand some concepts to make the corresponding changes, such as coreimage and UIView coordinate system is very different, one is the upper left corner of the screen as the Origin point, One is in the bottom left corner of the screen as the Origin point. In general, iOS contains the Uikit coordinate system (X-axis positive direction right, y-axis positive direction downward) and the standard Quartz 2D drawing coordinate system (X-axis positive direction right, y-axis positive direction upward), below, explaining some related concepts:

First, the bounds attribute of UIView

Defines a rectangle that describes the position and size of a uiview, noting that its reference system is itself, so the Bounds.origin property defaults to (0, 0), The bounds.size and frame.size are consistent, and the property is used primarily in methods related to view drawing. All the things that are drawn in the scope of the bounds are the visible contents of the view, and if you change the position of the bounds.origin, then what is drawn in the new location becomes the new visible content of the view (Will bounds.origin always or 0,0?). )

Second, the Frame property of UIView

Also defines a rectangle that describes the size and position of a uiview, but differs from the bounds property in that its reference system is the coordinate system of its parent view (Superview). This property is primarily used in geometric transformations that control the view, such as changes in view position and size.

Third, UIView's Center property

This property is used to determine the center point position of a view, which is the coordinate system of its parent view, just like the frame property. One effect of this property is that the value of the property does not change when you zoom in, out, or rotate the view, so you can use it to control the location of the views. Instead, the value of origin and size under this property will change if the frame property is used, so it is difficult to control the position of the view when the view changes.

Iv. some features

1. Changing the frame property affects both the Bounds property and the center property

2. Changing the center property will affect the origin value of the frame property

3. Changing the size value of the bounds property affects the size value of the Frame property (the Origin property of the Bounds property?). To do the experiment)

4, about the view clipping description, if the child view has partially exceeded the parent view, then the out part will also be drawn, unless the parent view has the Clipstobounds property set, and, in any case, the child view is outside the parent view's part, and will not respond to the child view's touch events.

5, coordinate system conversion: can be affine conversion (affine Transform) to a view of the coordinate system to do some transformation, so as to achieve the zoom, rotation and other functions of the view, but note two points, all of a view of the affine transformation is for its center-referenced The second is that affine transformations, although they can change the size and orientation of the view, are for their parent view, and for the application of the affine view, actually defines a coordinate corresponding to the transformation relationship, that is, its frame and other properties do not actually change (to do the experiment). Therefore, some position, size and other persistent changes should not be achieved by affine transformation, or should be by changing the frame properties, center properties and other ways to achieve. But temporary transformations, such as making rotational animations, using affine transformations are a good choice.

Two ways to implement affine transformations:
(1) Applying transformations to the entire view, you can use the SetTransform: Method of the view.
(2) The local drawing of the view can be transformed by using the DrawRect: method, if the corresponding graphics context is first transformed. In addition, using the view's DrawRect method also has a role to use to implement the view's position or size change. As long as we specify a transition relationship and draw the view at the specified location, we can achieve the same effect of changing the view size and position, and this is more efficient. At the same time, the DrawRect method should be applied to the bounds property of the view, which is always drawn from coordinates 0 o'clock, so it is also more convenient to use. Here are two diagrams of affine transformations to help you understand:

Reference article: View Programming Guide for IOS

---restore content ends---

iOS under Bound,center and frame

Related Article

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.