Search code examples
iosiphoneios7ios8

view frame does not move down 20px (height of the statusbar)


I used the code below to present vViewController1

  @property (retain,nonatomic) ViewController1 *vViewController1;

...

push vViewController1 from rootViewController

  [self.navigationController pushViewController:vViewController1 animated:NO];

Viewcontroller1's viewWillAppear

- (void) viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];


    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
        CGRect screen = [[UIScreen mainScreen] bounds];
        if (self.navigationController) {
            CGRect frame = self.navigationController.view.frame;
            frame.origin.y = 20;
            frame.size.height = screen.size.height - 20;
            self.navigationController.view.frame = frame;

        } else {
            if ([self respondsToSelector: @selector(containerView)]) {
                UIView *containerView = (UIView *)[self performSelector: @selector(containerView)];

                CGRect frame = containerView.frame;
                frame.origin.y = 20;
                frame.size.height = screen.size.height - 20;
                containerView.frame = frame;
            } else {
                CGRect frame = self.view.frame;
               frame.origin.y = 20;
               frame.size.height = screen.size.height - 20;
                self.view.frame = frame;

            }
        }
    }  

}

but it displays as below and does not move down 20px(height of the statusbar)

enter image description here

Your comment welcome


Solution

  • Assuming you are NOT using Autolayout (seeing as you are playing with frame sizes) then in Storyboard select the ViewController and then goto the Size Inspector (little ruler) and then adjust the Y delta for the view (change to 20 or -20 depending on what mode you are "View As").

    This may help here although I am not sure about the 18 value in Y I always thought it was 20!