AppleWatch视图生命周期

类似OC的视图生命周期

oc的视图生命周期分7步
init
loadView
viewDidLoad
viewWillAppear
viewDidAppear
viewWillDisappear
viewDidDisappear

而AppleWatch中似乎将前面的3步合到一起,直接初始化

后面的4步的话,watchOS1的时候并没有,视图已经出现和视图将要消失,是watchOS2之后才加入的.
//界面的初始化
    override func awakeWithContext(context: AnyObject?) {
        super.awakeWithContext(context)
    
        // Configure interface objects here.
    }

    //界面将要出现之前执行
    override func willActivate() {
        // This method is called when watch view controller is about to be visible to user
        super.willActivate()
    }

    //界面已经出现(watchOS2.0之后添加的)
    override func didAppear() {
        super.didAppear()
    }
    
    //界面将要消失(watchOS2.0之后添加的)
    override func willDisappear() {
        super.willDisappear()
    }
    
    
    //界面小时之后执行
    override func didDeactivate() {
        // This method is called when watch view controller is no longer visible
        super.didDeactivate()
    }

github地址:https://github.com/WWLJ/MoodTracker/tree/master

你可能感兴趣的:(AppleWatch视图生命周期)