When hiding the statusbar my navigation bar moves

2020-05-17 01:47发布

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 YES and then calling [self setNeedsStatusBarAppearanceUpdate];. The problem with this is that the navigationbar will slide up and won't leave space for the notification I'm trying to show. Simply adding a view over the statusbar is not an option, our statusbar/navigation has the fancy blur effect. Does anyone have a clue how to maintain the standard navigationbar height with the status bar height and remove the statusbar from that?

Edit; what I ended up doing is taking a risk and getting the UIWindow of the statusbar via a private API and offsetting that.

Edit 2; App got approved with the private API. Be cautious though!

5条回答
做自己的国王
2楼-- · 2020-05-17 02:30

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.

查看更多
干净又极端
3楼-- · 2020-05-17 02:31

Add this code in your view Controller:

if ([self respondsToSelector:@selector(setEdgesForExtendedLayout:)])
{
    self.edgesForExtendedLayout = UIRectEdgeNone;
}
查看更多
疯言疯语
4楼-- · 2020-05-17 02:40

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.

查看更多
forever°为你锁心
5楼-- · 2020-05-17 02:43

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

查看更多
等我变得足够好
6楼-- · 2020-05-17 02:49

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

查看更多
登录 后发表回答