0

A view in a view controller created using a nib has its frame at {0, 64, 320, 416}, origin starting right below the nav bar. In -loadView without a nib however, the view with the same frame is 44 pt off despite having the same frame (origin=(x=0, y=64) size=(width=320, height=416)), origin starting below the status bar, under the nav bar. Why is this and how can I match the nib behavior?

-(void)loadView
{
    CGRect f = EPFrame;
    if(self.navigationController)
    {
        f.size.height -= self.navigationController.navigationBar.bounds.size.height;
        f.origin.y += self.navigationController.navigationBar.bounds.size.height;

    }
    UIView *base = [[UIView alloc]initWithFrame:f];
    base.backgroundColor = [UIColor clearColor];
    self.view = base;

}
4

2 回答 2

2

There is no need, in this case, to implement the loadView method. By default the view controller will get an empty view. This view will be autosized to fit its container.

于 2013-07-04T05:41:10.967 回答
0

As I put the comment. You don't need to change view.frame.

self.view starts below navigation controller if it is enabled. If you don't have navigation self.view starts below status bar. If you hide status bar then self.view starts right from top of screen.

IOS takes care this internally. You don't need to do any code for this.

于 2013-07-04T05:40:34.353 回答