Wednesday, October 18, 2017

View Controller Programming Guide for iOS - Defining Your Subclass

View Controller Programming Guide for iOS

Defining Your Subclass

Displaying Your Views at Runtime

  1. Instantiates views using the information in your storyboard file. 
  2. Connects all outlets and actions. 
  3. Assigns the root view to the view controller’s view property. 
  4. Calls the view controller’s awakeFromNib method. (When this method is called, the view controller’s trait collection is empty and views may not be in their final positions. )
  5. Calls the view controller’s viewDidLoad method. (Use this method to add or remove views, modify layout constraints, and load data for your views.)
  6. Calls the view controller’s viewWillAppear: method to let it know that its views are about to appear onscreen. 
  7. Updates the layout of the views. 
  8. Displays the views onscreen. 
  9. Calls the viewDidAppear: method when the views are onscreen.
PS: When you add, remove, or modify the size or position of views, remember to add and remove any constraints that apply to those views. Making layout-related changes to your view hierarchy causes UIKit to mark the layout as dirty. During the next update cycle, the layout engine computes the size and position of views using the current layout constraints and applies those changes to the view hierarchy.

Managing View Layout

  1. Updates the trait collections of the view controller and its views
  2. Calls the view controller’s viewWillLayoutSubviews method.
  3. Calls the containerViewWillLayoutSubviews method of the current UIPresentationController object. 
  4. Calls the layoutSubviews method of view controller’s root view. The default implementation of this method computes the new layout information using the available constraints. The method then traverses the view hierarchy and calls layoutSubviews for each subview. 
  5. Applies the computed layout information to the views. 
  6. Calls the view controller’s viewDidLayoutSubviews method. 
  7. Calls the containerViewDidLayoutSubviews method of the current UIPresentationController object.

Good to know:

  • Use Auto Layout
  • Take advantage of the top and bottom layout guides
  • Remember to update constraints when adding or removing views
  • Remove constraints temporarily while animating your view controller’s views.

No comments :

Post a Comment