I have several UIViewControllers, loaded via a UINavigationController, where I override loadView, and setup a custom view to display. I am having problems with setting the frames of some of the subviews, and maybe the view itself. I think that either the UINavigationController or the UIViewController is able to force it's view to fill the screen when displayed.
I am wondering if and/or when the size of the view is set. And if it is happening, is it setting the frame of the view, or doing it another way.
Thanks.
Update: I have just noticed while working through this is that I make an new UINavigationController, with this loadView method:
- (void)loadView
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(10.0f, 10.0f, 10.0f, 10.0f)];
[view setBackgroundColor:[UIColor redColor]];
self.view = view;
[view release];
}
I get a red view taking up the entire screen, except for the status bar and header. When does my view get resized to fill the screen? And what size should I use when creating the view?
UINavigationController will automagically size a ViewController's view when pushed. From the docs:
pushViewController:animated:
The object in the viewController parameter becomes the top view controller on the navigation stack. Pushing a view controller results in the display of the view it manages. How that view is displayed is determined by the animated parameter. If the animated parameter is YES, the view is animated into position; otherwise, the view is simply displayed in place. The view is automatically resized to fit between the navigation bar and toolbar (if present) before it is displayed.
If you want to have a smaller view displayed then you'll have to create a container and make it a child of your VC's view, setting the size manually. The autoresize mask may have to be set properly, depending on how you create the view.
The framespace for the UIViewControllers
becomes smaller, because UINavigationController
manipulates the view by adding a UINavigationBar
, which is 44.0f in size.
It gets resized because you replace the view with self.view = view;
If you would have used addSubview:
instead it would have stayed it's original size. logancautrell explained when and why.
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