Document directory
- 1. Main Parameters
- Ii. Main Methods
- 3. Screen layout (subviews)
- Iv. Custom uiview
- 5. animation (animation & transition)
- Reference:
1. Main Parameters
1. contentmode: defines the filling mode of the uiview, such as uiviewcontentmodeleft, lag. In particular, uiviewcontentredraw. This is mandatory when a change (bounds or transform change) is triggered and drawrect is required to be re-painted, this parameter is rarely used.
2. contentstretch: When contentmode is set to stretch, this parameter determines the stretch range, expressed in units (0.0-1.0 ).
3. cliptobounds: whether to display the child view beyond the current view range.
4. Transform: deformation. Cgaffinetransform. note that the transform deformation only targets the rendered view and its subviews on the screen. It does not work for those that are not rendered, because each view only la S and provides content for its own bounds. In addition, if the transform is deformed, you cannot use the frame of the view to obtain the position and size. You must use bounds and center. After deformation, the frame of the view is nil.
5. contentscalefactor: the proportion of the screen used for high-resolution. The value is large, indicating that the larger the number of pixels the content occupies on the screen.
6. Tag: Obtain the view from the view's tree-list. One method is to use subviews for search, and the other is to use viewwithtag to find a specified view.
Ii. Main Methods
1. setneedsdisplay or setneedsdisplayinrect: Method for triggering drawrect
2. convertpoint (rect): fromview: convertpoint (rect): toview
3. setneedslayout or layoutifneeded
3. Screen layout (subviews)
1. Several events that trigger re-Layout
A) The view bounds has changed.
B) device direction changes
C) display the setneedslayout or layoutifneeded method that calls the view, or the setneedslayout method of a view layer.
D) The Sublayers of a view layer changes and requires layout.
2. Automatic Layout
A) autoresizessubviews is set to Yes
B) autoresizingmask sets an appropriate value for uiviewautoresizing to determine the layout.
C) even if the layout is completed automatically, you will be given the opportunity to manually adjust the layout and call the layoutsubviews method of view.
3. Manual Layout
Implementation Method: layoutsubviews. You may do the following similar work:
Adjust the size and position of subviews, add and delete subviews or corresponding Layers
Each subviews calls setneedsdisplay or setneedsdisplayinrect to re-draw the View content.
An example of layout is provided in the Apple document:
Assume that a scrollview has many views (tile views). When a scroll occurs, call the setneedslayout method of the root view. In layoutsubviews, the next image is displayed in a proper position, when scroll occurs when the current image exceeds the display area, call layoutsubviews to remove the view that exceeds the screen, or place it in the position of the next image.
Iv. Custom uiview
Follow these steps:
1. initwithframe and initwithcoder
2. dealloc
3. drawrect
4. autoresizingmask
5. Build subviews and set the appropriate autoresizingmask. If necessary, override layoutsubviews
6. Build touch events and Gesture Recognition
7. If printing is required, drawrect: forviewprintformatter:
In addition, you must set contentmode and contentstretch based on the actual situation, as well as some calayer settings (the layerclass method uses the specified default calayer type)
5. animation (animation & transition)
Unlike calayer, In transform, one is catransform3d and the other is caaffinetransform.
1. + (void) animatewithduration
2. + (void) beginanimations: Context
3. + (void) transitionwithview
4. In animation transaction, call + (void) setanimationtransition: forview: cache Method
Although caanimation and uiview animation can be used together in a block, Apple recommends that you use caanimation only for animation when both exist.
Reference:
View programming guide for iOS