Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When hiding the statusbar my navigation bar moves up in iOS7

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!

like image 415
Tim Wachter Avatar asked Oct 02 '13 13:10

Tim Wachter


People also ask

How do I hide and show navigation bar?

Touch “Settings” -> “Display” -> “Navigation bar” -> “Buttons” -> “Button layout”. Choose the pattern in “Hide navigation bar” -> When the app opens, the navigation bar will be automatically hidden and you can swipe up from the bottom corner of the screen to show it.

How do I change my Apple navigation bar?

On your Mac, use Dock & Menu Bar System Preferences to change the appearance of the Dock, and to select items to show in the menu bar and in Control Center. To change these preferences, choose Apple menu > System Preferences, then click Dock & Menu Bar .


4 Answers

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.

like image 153
Rahul Mathur Avatar answered Oct 23 '22 16:10

Rahul Mathur


Add this code in your view Controller:

if ([self respondsToSelector:@selector(setEdgesForExtendedLayout:)])
{
    self.edgesForExtendedLayout = UIRectEdgeNone;
}
like image 21
Tushar Avatar answered Oct 23 '22 15:10

Tushar


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

like image 1
iPatel Avatar answered Oct 23 '22 15:10

iPatel


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.

like image 1
Geet Avatar answered Oct 23 '22 17:10

Geet