Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The frame is not guaranteed to be the same in viewDidLoad as it will be when the view is eventually displayed. UIKit adjusts the frame of your view controller's view prior to displaying it, based on the context in which will appear. The size is determined based on interface orientation and the dimensions of any visible navigation bar, tab bar, toolbar, or status bar (which itself has a height that can change, e.g. when you're on a phone call).</p> <p>It helps to understand what happens when a view controller's view is loaded and displayed:</p> <ol> <li><p>Something accesses your view controller's <code>view</code> property for the first time. This may occur in your own code, or in UIKit in response to a user action like selecting a tab.</p></li> <li><p>UIKit lazy-loads your view controller's view by calling <code>loadView</code> if it's defined, or by loading the view from the NIB that was specified in <code>initWithNibName:bundle:</code>. If neither exists, UIKit just loads an empty view.</p></li> <li><p>UIKit calls <code>viewDidLoad</code> once the view and its subviews have been fully loaded. <strong><em>At this point the view's frame will be whatever it was set to in the NIB, or in <code>loadView</code>.</em></strong></p></li> <li><p>Something calls for UIKit to display your view controller's view. Again, this may be a user action like tapping on a tab, or an explicit method call in your code like <code>pushViewController:animated:</code> or <code>presentModalViewController:animated:</code>.</p></li> <li><p>UIKit resizes the view based on the context in which it will be presented, as described above.</p></li> <li><p>UIKit calls <code>viewWillAppear:</code>. <strong><em>The frame should now be the size that will be displayed.</em></strong> <em>(?) EDIT: This may no longer be true. See the comments below.</em></p></li> <li><p>UIKit displays the view, with or without animations.</p></li> <li><p>UIKit calls <code>viewDidAppear:</code>.</p></li> </ol> <p>As you can see, if you need to know the size of your view's frame before it gets presented, <code>viewWillAppear:</code> is your one and only opportunity. Just remember that this size may change after the view appears for various reasons, including rotation events or changes in status bar height. For this reason, it's important to give every subview an appropriate autoresizingMask, to ensure that the layout can adjust itself properly for any change in bounds.</p> <p>If you wish to build your view hierarchy manually, the recommended place to do so is in loadView. Since you construct the view yourself in this method, you can initialize its frame to whatever you'd like. The size you choose doesn't matter much, since UIKit is likely to change it on you anyway. Just make sure you set your autoresizingMasks appropriately.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload