Apple's docs say:
Note: Because the amount of space available for the custom view can vary
(depending on the size of the other navigation views), your custom view’s
autoresizingMask property should be set to have a flexible width and height.
Before displaying your view, the navigation controller automatically
positions and sizes it to fit the available space.
That's great, except ... I need to know the size UINavController will use BEFORE the view is added to the frame, because the content I'll be displaying is different depending on the size.
This is inside the "loadView" method of a UIViewController that's being added to the UINavigationController.
Well, technically you shouldn't be sizing your subviews in the loadView method. I don't use nibs, and in almost all of my view controllers the loadView is really small: self.view = [[UIView alloc] init];. Then, in viewDidLoad I add all my subviews to self.view. Finally, I do all of my resizing in viewWillAppear, because at that point self.view will be the appropriate size.
If you must size views in the loadView method, you'll have to calculate out the dimensions manually...i.e: find out the orientation of the device (self.interfaceOrientation) determine the screen size, subtract out whatever other elements you think are on screen (like a Navigation bar, etc). But this method is not recommended.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With