Note that there are some explanatory texts on larger screens.

plurals
  1. POLaying out & sizing of subviews in a UIViewController
    primarykey
    data
    text
    <p>I have an app with with a <code>UITabController</code> and each tab is a <code>UINavigationController</code>. The root of one of my <code>UINavigationControllers</code> is a <code>UIViewController</code>.</p> <p>Inside that view controller's view, I want to layout some subviews, but I'm confused as to where &amp; how to lay them out in a way that will be resolution independent (i.e. not hardcode values such as 320px, 480px, 44px, etc.).</p> <p>When the view is fully loaded and presented on a vertical iPhone, it's height will be 367px = 480 - 20 (status bar) - 44 (nav bar) - 49 (tab bar).</p> <p>Inside the view controller, I currently create all my subviews within the <code>viewDidLoad</code> method. However, it appears that within this method, the view's current height is 460px (<code>self.view.bounds.size.height</code>). So when setting up my subviews, I cannot properly calculate the sizes of anything.</p> <p>Within the <code>viewWillAppear:</code> method, the view <strong>does</strong> know it's proper size, but that would mean setting &amp; calculating the subview's frames every time the view will appear (e.g. tab changes or popping from child view controllers on the navigation stack.</p> <p>Is the only way to do this properly to layout in <code>viewWillAppear:</code>?</p> <p>I have tried using the autoresizing properties (parent's <code>autoresizesSubviews</code> &amp; <code>autoresizingMask</code>) but they don't seem to work at all!? Do these only take effect once the view is all setup and then it is resized (manually / orientation change?).</p> <p>I'd be grateful if someone could let me know why the autoresizing isn't working, and how best to lay things out by not hardcoding any sizes.</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.
 

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