1. Init initialization does not trigger Layoutsubviews
2, Addsubview will trigger Layoutsubviews
3, set the view frame will trigger the layoutsubviews, of course, if the frame value has changed before and after the setting
4, rolling a uiscrollview will trigger layoutsubviews
5. Rotate screen will trigger the Layoutsubviews event on the parent UIView
6, change the size of a uiview will also trigger the parent UIView on the Layoutsubviews event
7, call Setlayoutsubviews directly. The drawrect is called in the following cases:
1. If the rect size is not set at UIView initialization, the drawrect will not be automatically called. DrawRect is in Controller->loadview, right? Controller->viewdidload? The two methods are then dropped. So don't worry. In the controller, these view drawrect begin to draw. This allows you to set some values in the controller to the view (if these view? Some variable values are required for draw).
2, this method is called after calling SizeToFit, so you can call SizeToFit to calculate the size first. The system then automatically calls the DrawRect: method.
3, by setting the Contentmode property value to Uiviewcontentmoderedraw. The drawrect will be called automatically each time the frame is set or changed:.
4. Call Setneedsdisplay directly, or setneedsdisplayinrect: Trigger DrawRect:, but there is a precondition that rect cannot be 0.
Above 1, 2 recommended; and 3,4 does not advocate? DrawRect methods use note points:
1, if using UIView drawing, only in the DrawRect: method to obtain the corresponding Contextref and drawing. If obtained in other methods, it gets to a invalidate ref and cannot be used for paint. DrawRect: The method cannot manually display the call, and the system must be automatically tuned by calling Setneedsdisplay? or Setneedsdisplayinrect.
2, if using Calayer drawing, can only be drawn in Drawincontext:? (similar to DrawRect), or in the corresponding method in delegate. Also call Setneeddisplay and so on indirectly call the above method
3, for real-time drawing, cannot use Gesturerecognizer, can only use Touchbegan and other methods to call Setneedsdisplay real-time refresh screen
Layoutsubviews will be called in the following cases