33

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!

Tim Wachter
  • 732
  • 5
  • 22
  • A `UINavigationBar` is a `UIView` subclass. Set its frame to whatever you want. If you're using a `UINavigationController` which is setting its frame, subclass that and override `viewWillLayoutSubviews`. – Aaron Brager May 30 '14 at 07:49
  • Full investigation: http://stackoverflow.com/questions/21929220/show-hide-uitoolbar-match-finger-movement-precisely-as-in-for-example-ios7-s – Fattie Jun 01 '14 at 16:09
  • check this reference link [customize-navigation-status-bar-ios-7](http://www.appcoda.com/customize-navigation-status-bar-ios-7/) – Pawan Rai Jun 02 '14 at 12:16
  • Some screenshots to understand what, and more important why you want to do this could help. – Rivera Jun 04 '14 at 02:32
  • Can you post a snapshot? – Gajendra K Chauhan Jun 05 '14 at 03:59

5 Answers5

3

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.

Kumar KL
  • 15,315
  • 9
  • 38
  • 60
Rahul Mathur
  • 872
  • 1
  • 7
  • 20
  • 1
    customView height should be `self.view.frame.size.height - 20` :) – iPatel Jun 05 '14 at 11:05
  • The bounty was automatically awarded, but the answer is mostly correct. I solved my problem by making a replacement `UINavigationView` class that I manually add to my views, while the real navigation bar of my controllers stays hidden. Although I DO use a view-controller based status bar appearance plist item and override `prefersStatusBarHidden` – user Jun 06 '14 at 18:17
2

Add this code in your view Controller:

if ([self respondsToSelector:@selector(setEdgesForExtendedLayout:)])
{
    self.edgesForExtendedLayout = UIRectEdgeNone;
}
Tushar
  • 88
  • 7
1

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.

Sushil Sharma
  • 2,321
  • 3
  • 29
  • 49
Geet
  • 2,427
  • 2
  • 21
  • 39
1

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

Community
  • 1
  • 1
iPatel
  • 46,010
  • 16
  • 115
  • 137
  • hello, i am working with TLYShyNavBar and carbonkit for navigationbar hide like youtube home page you have idea about this ? – ramesh bhuja Sep 02 '16 at 07:53
0

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

dopcn
  • 4,218
  • 3
  • 23
  • 32