iT邦幫忙

第 11 屆 iThome 鐵人賽

DAY 30
0
自我挑戰組

Hello Swift系列 第 30

30/30 命裡無時莫強求

  • 分享至 

  • xImage
  •  

Life cycle of View 生命週期
loadView:用程式碼產生畫面

viewDidLoad:讀入畫面之後執行
第一個載入的方法,可以按照自己希望App一開始呈現的畫面來設定。
只有在一開始執行App時呼叫一次。

viewWillAppear:畫面即將顯示到螢幕上

viewDidAppear:畫面已經顯示到螢幕上
當畫面呈現給使用者時,就呼叫此方法,每次進入畫面時都會呼叫。

viewWillDisappear:畫面即將離開螢幕
veiwDidDisappear:畫面已經離開螢幕

ViewController.swift

override func viewDidLoad() {
        super.viewDidLoad()
        print("view: did load")
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        print("view: will appear")
    }
    
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        print("view: did appear")
    }
    
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        print("view: will disapper")
    }

    override func viewDidDisappear(_ animated: Bool) {
        super.viewDidAppear(animated)
        print("view: did disappear")
    }

}

AppDelegate.swift

func application(_ application: UIApplication,     didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool{
    print("app: did finishing launching")
    return true
}

func applicationWillResignActive(_ application: UIApplication){
    print("app: will resign active")
}

func applicationDidEnterBackground(_ application: UIApplication){
    print("app: did enter background")
}

func applicationWillEnterForeground(_ application: UIApplication){
    print("app: did enter foreground")
}

func applicationDidBecomeActive(_ application: UIApplication){
    print("app: did become active")
}

func applicationWillTerminate(_ application: UIApplication){
    print("app: will terminate")
}


上一篇
29/30 命裡有時終須有
系列文
Hello Swift30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 則留言

0
Howard
iT邦新手 4 級 ‧ 2019-10-16 22:04:37

賀完賽/images/emoticon/emoticon64.gif

我要留言

立即登入留言