Hetal Vora
Hetal Vora

Reputation: 3361

view jumps when navigation bar hidden

In our app when one of the view is pushed to the navigation controller, the navigation bar is visible for 5 seconds and then we set navigationBarHidden to TRUE. Later if the user taps on the screen we toggle navigationBarHidden values. But as the navigation bar id hidden or is made visible, the view jumps up and down respectively for these actions.

Is there any way I can prevent the view from jumping when the bar is hidden or made visible?

Thanks and Regards, Hetal

Upvotes: 4

Views: 4194

Answers (4)

Valerika
Valerika

Reputation: 474

In SwiftUI use hidden() methods, and it is important to create a title, even an empty one. If you use NavigationLink, apply methods for both views to avoid a "jumpy" effect.

 .navigationBarTitle("")   
 .navigationBarHidden(true)
 .labelsHidden()

Upvotes: 2

Devin
Devin

Reputation: 183

I realize this is an old conversation, but I was having trouble with this in iOS 11 with some previously working code, and this was the first result I kept getting in Google.

In my case, I have a view controller with a navigation controller. The view contains a scroll view.

If the scroll view is zoomed in all, the scroll position will jump after the navigation bar hide/show animation.

Setting self.automaticallyAdjustsScrollViewInsets = NO/false did not work (where it did up through iOS 10).

After much fiddling around, I realized there is a new property in UIScrollView called contentInsetAdjustmentBehavior.

I had to set this to "never" to get the desired affect (i.e. scroll view position does not change when showing/hiding the navigation bar).

In swift it looks like this: self.scrollView?.contentInsetAdjustmentBehavior = .never

Upvotes: 1

JZAU
JZAU

Reputation: 3567

I have the same problem. In my project, it is because the view is scroll view. If your view is a scroll view or table view, you can try this:

I add below code to the controller.

self.automaticallyAdjustsScrollViewInsets = NO;

Hope it can help you.

Upvotes: 7

Domestic Cat
Domestic Cat

Reputation: 1434

Are you using setNavigationBarHidden: or setNavigationBarHidden:animated:?

Try [navigationController setNavigationBarHidden:NO animated:YES];.

If the issue is the view changing size then you will have to account for that in the view itself, ie it will have to be able to handle both sizes.

Upvotes: 4

Related Questions