iOS開發:視圖生命週期

 

iOS應用的視圖狀態分爲如下幾種app

  • 在viewcontroller的父類UIViewController中能夠看到以下代碼,經過重寫不一樣的方法對操做視圖渲染。
@available(iOS 2.0, *)
public class UIViewController{
 
   public func viewDidLoad() // Called after the view has been loaded. For view controllers created in code, this is after -loadView. For view controllers unarchived from a nib, this is after the view is set.
   public func viewWillAppear(animated: Bool) // Called when the view is about to made visible. Default does nothing
    public func viewDidAppear(animated: Bool) // Called when the view has been fully transitioned onto the screen. Default does nothing
    public func viewWillDisappear(animated: Bool) // Called when the view is dismissed, covered or otherwise hidden. Default does nothing
    public func viewDidDisappear(animated: Bool) // Called after the view was dismissed, covered or otherwise hidden. Default does nothing
public func didReceiveMemoryWarning() // Called when the parent application receives a memory warning. On iOS 6.0 it will no longer clear the view by default.
 
}
    • viewDidLoad():視圖被加載到內存中時調用viewDidLoad方法,在該方法中可對視圖上佈局進行調整
    • viewWillAppear():視圖可見前
    • viewDidAppear():視圖已經可見,頁面渲染完成後能夠加載一些控件動畫
    • viewWillDisappear():視圖失去焦點前
    • viewWillDidDisappear():視圖失去焦點後
    • didReceiveMemoryWarning():在iOS 6以後可以使用此方法釋放內存,包括視圖控制器中的一些成員變量
相關文章
相關標籤/搜索