views:

423

answers:

1

I have a custom UIViewController and a corresponding view in a nib file. The view is added to the UIWindow directly.

[window addSubview:customViewController.view];

Sizes of the window and the view are default (480x320 and 460x320 correspondingly).

When I create CustomViewController inside the nib file and check "Resize View From NIB" in IB Attributes tab everything works just fine.

But when I create CustomViewController programmmatically with initWithNibName message the view is not positioned on the window correctly. There is an empty stripe at the bottom. Its height is 20px. I see it's because of status bar offset.

IB handles that with "Resize View From NIB". How to emulate that programmatically?

It seems that IB uses some custom subclass of UIViewController. So the question: how is "Resize View From NIB" implemented there?

+1  A: 

When I want to make sure the view covers the whole screen, I do something like this:

- (void) viewWillAppear: (BOOL) animated
{
    [super viewWillAppear:animated];
    [[self view] setFrame:[[UIScreen mainScreen] bounds]];
}

Feels like a hack, so I do it only as a last resort, when I can’t get the view to behave otherwise :)

zoul
Tried, but it doesn't work for me. The same stripe at the bottom appears.
alexey
[[self view] setFrame:CGRectMake(0, 20, 320, 480)];This works, but looks like some kind of hardcoding.[[UIScreen mainScreen] bounds]] returns (0, 0, 320, 480).
alexey