When hiding the statusbar my navigation bar moves up in iOS7

给你一囗甜甜゛ 提交于 2019-12-09 04:07:04

问题


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!


回答1:


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.




回答2:


Add this code in your view Controller:

if ([self respondsToSelector:@selector(setEdgesForExtendedLayout:)])
{
    self.edgesForExtendedLayout = UIRectEdgeNone;
}



回答3:


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




回答4:


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.




回答5:


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



来源:https://stackoverflow.com/questions/19137559/when-hiding-the-statusbar-my-navigation-bar-moves-up-in-ios7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!