IPhoneDeveloping applicationsUIViewWhat do you know? Let's continue with the previous article about the UIView development process of iPhone development applications. Someone once said that what you see on the iphone isUIView, SoUIViewInIphoneIt plays an important role in development.
Coordinate System conversion matrix
Coordinate System conversion matrix changeViewOr itsView) Provides a simple and easy way. An affine conversion is a mathematical matrix that specifies how points in the coordinate system are mapped to points in another coordinate system. You canViewApply the affined conversion, based on its parentViewTo changeView. You can also apply the affine conversion in your drawing code to perform the same operation on the independent parts of the explained content. How to apply the affine conversion is based on the context:
To modify the entire view, you can modify the affined conversion value of the view transform attribute.
To modify the specified part of the content in the drawRect: Method in the view, you can modify the affine conversion related to the current image context.
When you want to implement an animation, you can usually modify the transform attribute value of the view. For example, you can use this attribute to create an animation for the view to flip around the center point. You should not use this attribute in the coordinate space of its parent view to permanently change your view, such as modifying its position and size. For this type change, you can modify the frame rectangle of the view.
Note: When modifying the transform attribute value of a view, all conversions are implemented based on the center point of the view.
In the drawRect: Method of a view, you can use the affine conversion to locate or flip the project you want to draw. Compared with modifying the object location in some parts of the view, we prefer to create an object relative to a fixed point, usually 0, 0), and use the conversion to locate the object before painting. In this case, if the position of the object in the view changes, all you need to do is modify the conversion matrix, which is better than re-creating a new position for the object. You can use the CGContextGetCTM method to obtain the affine conversion of the graphic context. You can also use the Core Graphics method to set or modify the conversion matrix in the painting.
The current conversion matrix CTM) is an affine matrix used at any time. When controlling the geometric structure of the entire view, CTM is the value of the view transform attribute. In the drawRect: method, CTM is an affine matrix about the graphic context.
The coordinate system of each sub-view is built on the coordinate system of its ancestor. Therefore, when you modify the transform attribute of a view, this change will affect the view and all its subviews. However, these changes only affect the final interpretation of the on-screen view. Because each view is responsible for drawing its own content and layout its child views, it can ignore the conversion of the parent view during painting and layout.
Figure1-6 describes how two different conversion factors are visually combined during interpretation. In the drawRect: Method of a view, applying a 45 degree Conversion factor to a shape will flip the specified angle. A 45-degree conversion factor will flip the entire shape 90 degrees. This shape is still flipped 45 degrees for the view that draws it, but the view's own conversion makes it look like it has flipped 90 degrees.
Figure 1-6 flip a view and its content
Important: If the transform attribute of a view is not the conversion matrix when it is defined, the frame attribute of the view is undefined and must be ignored. When converting a view, you must use the bounds and center attributes of the view to obtain the position and size of the view. The frame rectangle of the subview is still valid because they are related to the bounds of the view.
Obtain