When hiding the statusbar my navigation bar moves up in iOS7

前端 未结 5 492
逝去的感伤
逝去的感伤 2021-01-31 16:05

I am trying to hide the statusbar but maintain the \"bigger\" navigationbar height. Right now when I hide the statusbar by setting - (BOOL)prefersStatusBarHidden to

相关标签:
5条回答
  • 2021-01-31 16:41

    Add this code in your view Controller:

    if ([self respondsToSelector:@selector(setEdgesForExtendedLayout:)])
    {
        self.edgesForExtendedLayout = UIRectEdgeNone;
    }
    
    0 讨论(0)
  • 2021-01-31 16:42

    I had to do this once. I ended up creating a custom navigationBar of my own and then just set the frame as:

    navBar.frame=CGRectMake(0, 20, self.view.frame.size.width, self.view.frame.size.height);
    

    It worked for me at the time. Just try it out.

    0 讨论(0)
  • 2021-01-31 16:50

    You should use of positionForBar: method of UIBarPositioningDelegate Protocol.

    I don't want to put another answer or copy/past so you should take closer look at following question\answers. :)

    iOS 7 Status Bar Collides With NavigationBar
    iOS 7 UIToolBar Overriding With Status Bar
    statusbar overlapping content in iOS7

    0 讨论(0)
  • 2021-01-31 16:54

    Another workaround here: subclass UINavigationController override method:

    - (void)viewWillLayoutSubviews
    {
        [super viewWillLayoutSubviews];
        if (self.navigationBar.frameMinY < 1) {
            self.navigationBar.frameHeight = 64;
        } else {
            self.navigationBar.frameHeight = 44;
        }
    }
    

    in which set frameMinY is set frame.origin.y and set frameHeight is set frame.size.height

    0 讨论(0)
  • 2021-01-31 17:01

    You can create a custom UIView with its frame as

    customView.frame=CGRectMake(0, 20, self.view.frame.size.width, self.view.frame.size.height);
    

    Also hide your status bar by following the below steps

    Go to info.plist and add two attributes if not present. set "Status bar is initially hidden" to YES and set UIViewControllerBasedStatusBarAppearance to NO. This will hide status bar for your app.

    0 讨论(0)
提交回复
热议问题