0
votes

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;

}
2
you dont need to adjust view for navigation. It x and y starts below navigation bar. So don't increase y. It will work fine.Durgaprasad

2 Answers

2
votes

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.

0
votes

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.