setNeedsLayout 調用時會調用 - (void)layoutSubviews html
setNeedsLayout 在Doc中的定義爲: ios
Call this method on your application’s main thread when you want to adjust the layout of a view’s subviews. This method makes a note of the request and returns immediately. Because this method does not force an immediate update, but instead waits for the next update cycle, you can use it to invalidate the layout of multiple views before any of those views are updated. This behavior allows you to consolidate all of your layout updates to one update cycle, which is usually better for performance. app
- (void)layoutSubviews方法在doc中的定義爲: ide
The default implementation of this method does nothing on iOS 5.1 and earlier. Otherwise, the default implementation uses any constraints you have set to determine the size and position of any subviews. this
Subclasses can override this method as needed to perform more precise layout of their subviews. You should override this method only if the autoresizing and constraint-based behaviors of the subviews do not offer the behavior you want. You can use your implementation to set the frame rectangles of your subviews directly. spa
You should not call this method directly. If you want to force a layout update, call the setNeedsLayout method instead to do so prior to the next drawing update. If you want to update the layout of your views immediately, call the layoutIfNeeded method. code
由上可見,layoutSubviews 方法是用來設定subview的位置的方法, 是不能手動調用的。只能經過調用setNeedsLayout 方法,來讓系統自動調用layoutSubviews方法。 orm
setNeedsDisplay 調用時, 系統會自動調用 drawRect 方法。 htm
setNeedsDisplay 在Doc中的定義以下: ip
You should use this method to request that a view be redrawn only when the content or appearance of the view change. If you simply change the geometry of the view, the view is typically not redrawn. Instead, its existing content is adjusted based on the value in the view’s contentMode property. Redisplaying the existing content improves performance by avoiding the need to redraw content that has not changed.