Method | Class/Protocal | Description |
---|---|---|
+ (void)load |
NSObject | 1、Invoked whenever a class or category is added to the Objective-C runtime(class和category添加到runtime时调用) 2、A class’s +load method is called after all of its superclasses’ +load methods(class在superclass后调用)3、A category +load method is called after the class’s own +load method(category在class后调用) |
+ (void)initialize |
NSObject | 1、Initializes the class before it receives its first message.(在收到第一条消息之前初始化类) 2、 Superclasses receive this message before their subclasses.(superclass先调用) 3、The runtime sends the initialize message to classes in a thread-safe manner.(线程安全) |
- (instancetype)init |
NSObject | 1、In a custom implementation of this method, you must invoke super’s Initialization then initialize and return the new object.(必须调用super的init) |
- (instancetype)initWithFrame:(CGRect)frame |
UIView | 1、The origin of the frame is relative to the superview in which you plan to add it. (原点相对于父视图) 2、If you create a view object programmatically, this method is the designated initializer for the UIView class.(以编程方式创建视图对象,则此方法是UIView类的指派初始化方法) 3、 Subclasses can override this method to perform any custom initialization but must call super at the beginning of their implementation.(子类必须调用super) 4、If you use Interface Builder to design your interface, this method is not called when your view objects are subsequently loaded from the nib file.(使用Interface Builder创建,从nib文件加载视图对象时不会调用此方法) |
- (instancetype)initWithCoder:(NSCoder *)aDecoder |
NSCoding | 1、Objects in a nib file are reconstituted and then initialized using their initWithCoder: method, which modifies the attributes of the view to match the attributes stored in the nib file. (nib文件中的对象使用initWithCoder: 完成初始化和属性修改) |
- (void)awakeFromNib |
NSObject | 1、The nib-loading infrastructure sends an awakeFromNib message to each object recreated from a nib archive, but only after all the objects in the archive have been loaded and initialized.(nib文件中的所有对象被加载和初始化后收到该消息) 2、When an object receives an awakeFromNib message, it is guaranteed to have all its outlet and action connections already established.(收到消息时,所有的IBOutlet和IBAction已经连接完毕) 3、You must call the super implementation of awakeFromNib to give parent classes the opportunity to perform any additional initialization they require.(需要调用super) 4、Objects that conform to the NSCoding protocol (including all subclasses of UIViewand UIViewController) are initialized using their initWithCoder: method.(符合NSCoding协议的对象使用initWithCoder:初始化) |
- (void)loadView |
UIViewController | 1、You should never call this method directly. The view controller calls this method when its view property is requested but is currently nil. This method loads or creates a view and assigns it to the view property.(不要直接调用,ViewController访问view属性但其为nil时调用) 2、If you use Interface Builder to create your views and initialize the view controller, you must not override this method.(如果使用IB,不应该覆写此方法) 3、You can override this method in order to create your views manually.If you choose to do so, assign the root view of your view hierarchy to the view property.(手动创建视图时可以覆写) 4、Your custom implementation of this method should not call super.(不调用super) 5、If you want to perform any additional initialization of your views, do so in the viewDidLoad method.(其他初始化操作在 viewDidLoad 方法执行) |
- (void)viewDidLoad |
UIViewController | 1、This method is called after the view controller has loaded its view hierarchy into memory.(视图控制器加载视图结构到内存后调用) 2、This method is called regardless of whether the view hierarchy was loaded from a nib file or created programmatically in the loadView method.(无论IB还是编码方式都会调用) |
- (void)viewWillAppear:(BOOL)animated |
UIViewController | 1、This method is called before the view controller'��s view is about to be added to a view hierarchy and before any animations are configured for showing the view.(添加到视图层次之前调用) 2、If you override this method, you must call super at some point in your implementation.(必须调用super) 3、If a view controller is presented by a view controller inside of a popover, this method is not invoked on the presenting view controller after the presented controller is dismissed. |
- (void)viewDidAppear:(BOOL)animated |
UIViewController | 1、If you override this method, you must call super at some point in your implementation. 2、If a view controller is presented by a view controller inside of a popover, this method is not invoked on the presenting view controller after the presented controller is dismissed. |
- (void) viewWillLayoutSubviews |
UIViewController | 1、Called just before the view controller's view's layoutSubviews method is invoked. |
- (void) viewDidLayoutSubviews |
UIViewController | 1、Called just after the view controller's view's layoutSubviews method is invoked. |
- (void)willMoveToParentViewController:(UIViewController *)parent |
UIViewController | 1、Called just before the view controller is added or removed from a container view controller. |
- (void)didMoveToParentViewController:(UIViewController *)parent |
UIViewController | 1、Called after the view controller is added or removed from a container view controller. |
- (void)drawRect:(CGRect)rect |
UIView | 1、 You do not need to override this method if your view sets its content in other ways.(如果视图仅是设置其内容无需覆盖此方法) 2、If you subclass UIView directly, your implementation of this method does not need to call super.However, if you are subclassing a different view class, you should call super at some point in your implementation.(如果直接子类化UIView,方法的实现不需要调用super。但如果要子类化其他视图类,则应在实现中的某个时刻调用super) 3、This method is called when a view is first displayed or when an event occurs that invalidates a visible part of the view. (首次显示视图或发生使视图的可见部分无效的事件时,将调用此方法) 4、You should never call this method directly yourself. (不应该直接调用这个方法) |
- (void)layoutSubviews |
UIView | 1、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.(iOS5.1及更早版本默认实现不起作用,之后版本用来确定子视图位置大小) 2、Subclasses can override this method as needed to perform more precise layout of their subviews. (子类可以重写方法,进行更精确的布局) 3、You should not call this method directly. 4、If you want to force a layout update, call the setNeedsLayout method instead to do so prior to the next drawing update. (如果要强制布局更新,请在下次图形更新之前调用setNeedsLayout方法)5、If you want to update the layout of your views immediately, call the layoutIfNeeded method. (如果要立即更新视图的布局,请调用layoutifneeded方法) |
- (void)setNeedsLayout |
UIView | 1、Invalidates the current layout of the receiver and triggers a layout update during the next update cycle.(设置当前布局无效并在下一个更新周期触发布局更新) 2、Call this method on your application’s main thread when you want to adjust the layout of a view’s subviews.(在主线程调用) 3、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. (此方法记录并立即返回,不强制立即更新而是等待下一个更新周期) 4、This behavior allows you to consolidate all of your layout updates to one update cycle, which is usually better for performance. (此行为允许您将所有布局更新合并到一个更新周期,这通常对性能更好) |
- (void)layoutIfNeeded |
UIView | 1、Use this method to force the view to update its layout immediately. |
网友评论