Resizing view when loading from a .nib file
I have a .nib file created in Interface Builder with 1 UIView item, but when I initialize it programmatically, the view doesn't cover up the entire screen, leaving a small portion of the view beneath it visible.
It looks like the Y coordinate is at some negative position instead of at 0. I don't have a Navigation bar configured for the view but if I were to set it, the bar doesn't get shown.
I'm creating the view like this inside the appDelegate class:
MyCustomController *controller = [[MyCustomController alloc] initWithNibName:@"MyCustomView" bundle:nil];
[window addSubview:[controller view]];
Settings in Interface Builder for the v开发者_如何学运维iew:
Orientation: Portrait
Status Bar: Gray
Top Bar: unspecified
Bottom Bar: unspecified
View mode: "Scale To Fill"
View Size/Position: Set to "Layout" and the X/Y, Width/Height are readonly with 0,0,320,460
I've printed out the view's frame and [[UIScreen mainScreen] bounds] on 'viewWillAppear':
view.frame on viewWillAppear - x: 0.0, 0.0, 320.0, 460.0
bounds - x: 0.0, 0.0, 320.0, 480.0
I'm not sure why the view is getting shifted - what's the best place to read just the frame size once the view is loaded by the 'initWithNibName' method? That seems to be the workaround I can think of.
I wrapped my controller with a UINavigationController and the problem went away.
精彩评论