Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hiding Nav Bar moves view "up"

Tags:

ios7

The usual story -- I'm making an iOS 5/6 app run under iOS 7 and the navigation bar behavior change is causing a problem.

The app already worked like the iOS 7 default with a full-screen view and a translucent nav bar "over" of the view. The problem is that hiding/un-hiding the nav bar causes different behavior in iOS 7. On iOS 5/6 hiding/un-hiding the nav bar does not change the view. On iOS 7, hiding the bar visually moves the view up leaving a blank bar at the bottom of the screen and un-hiding the bar moves the view back down to occupy the full screen (with the nav bar on top, of course).

I need to continue to support iOS 5 so I don't use auto layout, but I do use the full screen. I have a view in which I'm viewing a zoomable image -- so the view controller has a fullscreen view containing a scrollView which contains an imageView.

The status bar is always hidden.

I get to the view controller via a navigation controller so there is a (black, translucent) navigation bar which lies over the top of my fullscreen view/scrollView/imageView.

After a brief delay some overlaying labels fade and the navigation bar is hidden A single tap restores the overlay labels and un-hides the navigation bar. This works on iOS 5/6 -- the navigation bar slides off the top of the screen uncovering the top of the view/image.

On iOS 7, when the navigation bar slides off the top of the screen the entire view visually moves up a corresponding amount (i.e. 44 points) leaving a black bar at the bottom of the screen. I can see this by setting a background color on the top-level view and resizing the scrollview enough to see the background; the top of the view does indeed move offscreen and the background color is not drawn over the bottom (44 points) of the screen.

BUT, self.view.frame doesn't change and remains at {0, 0} 320 x height.

When I single-tap to restore the overlay info and navigation bar the view moves back down to occupy the full screen and the translucent nav bar is over the top of the view/image.

Nothing I've tried changes the behavior: Changing the IB view controller layout controls (Under top bars, Under bottom bars, Adjust scroll view insets). Building for 5.1, 6.1, and 7.0 all produce the same result when run under 7.0.

self.edgesForExtendedLayout = UIRectEdgeNone

does nothing. Using the layout delta values doesn't do anything. In IB the view looks the same when "viewed as" iOS 7 and iOS 6 and earlier. I print out a lot of debug info but nothing about the view (or scroll view) seems to change when the view moves "off screen".

The code that shows the overlay info (run when the view is first shown and on single-taps) is:

- (void) showOverlayInfo {
    self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
    [[[self navigationController] navigationBar] setTranslucent:YES];
    [[self navigationController] setNavigationBarHidden:NO animated:NO];    

    overlayInfoHidden = NO;
    overlayInfoFading = NO;
    self.infoButton.hidden = NO;
    self.infoButton.alpha = 1;
    self.descriptionLabel.hidden = NO;
    self.descriptionLabel.alpha = 1;
}

The code that hides the overlay info is:

- (void) hideOverlayInfo {
    overlayInfoHidden = YES;
    overlayInfoFading = NO;
    self.infoButton.hidden = YES;
    self.descriptionLabel.hidden = YES;
    [[self navigationController] setNavigationBarHidden:YES animated:YES];
}

So can anybody tell me what (presumably simple) thing I'm missing?

like image 362
Charlie Price Avatar asked Oct 23 '13 15:10

Charlie Price


People also ask

How do I completely hide my navigation bar?

If you want to view files or use apps in full screen, double-tap the Show and hide button to hide the navigation bar. To show the navigation bar again, drag upwards from the bottom of the screen.

What is hide in navigation?

Hiding from your navigation will not hide the page from search engines or your site map; it only prevents it from showing in your navigation.

How do I hide the top navigation bar in Swift?

How To Hide Navigation Bar In Swift. To hide the navigation bar in Swift, you'll need to add code to two methods: viewWillAppear and viewWillDisappear . That's it to hide the navigation bar in your view controller.


1 Answers

I finally found my problem.

The key fact is that the image-viewer view controller was in a UIPageViewController, so what I was looking at and experimenting with was really "inside" another view controller. Although I had disabled the view controller setting Adjust Scroll View Insets for the image viewer VC, I hadn't done it for the containing VC that created the UIPageViewController and the UIPageViewController presents the pages in some subclass of a UIScrollView. When I changed them for the parent VC, the problem vanished.

So I think the moral of the story is to:

  • Think about the problem more globally when local doesn't work because maybe you're missing some important context.
  • If you don't want to use the iOS 7 behavior, change the settings for every single view controller you have!
like image 190
Charlie Price Avatar answered Jan 04 '23 15:01

Charlie Price