View frame changes between viewWillAppear: and viewDidAppear:

前端 未结 4 1940
慢半拍i
慢半拍i 2020-11-28 22:57

I have discovered a strange behavior in my application, where a connected IBOutlet has its connected view\'s frame between the calls in my view controller to

4条回答
  •  北海茫月
    2020-11-28 23:41

    From the documentation:

    viewWillAppear:
    

    Notifies the view controller that its view is about to be added to a view hierarchy.

    viewDidAppear:
    

    Notifies the view controller that its view was added to a view hierarchy.

    As a result the frames of the subviews aren't yet set in the viewWillAppear:

    The appropriate method to modify your UI before the view is presented to the screen is:

    viewDidLayoutSubviews
    

    Notifies the view controller that its view just laid out its subviews.

提交回复
热议问题