View size with setting navigation bar to hide using push / pop

So, before I push the new viewController onto the stack in a specific view, I set hiddenBar to hidden. I notice that it disappears before the next screen is pressed and the slide animation happens (because I need the UIToolbar at the top),

So, question number 1: is there a way to click on the new view controller and hide the navigation bar, and not get the hide animation until the new view controller appears on the screen. It looks funny that the navigation bar is hiding and then popping a new view controller.

As soon as the new view controller appears, when I pulled it out, I set the navigation bar back

[self.navigationController.navigationBar setHidden:NO]; 

But when it pops up, the navigation bar no longer returns. Is it because this navigationBar is for the current navigation controller and not the new one that appears after pop music? (question number 2)

Question 3: Understanding that it does not show my navigationBar, in the viewController that appears after pop, in its viewDidAppear, I added

 - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; [self.navigationController.navigationBar setHidden:NO]; } 

which shows the navigation, but the size of the view is incorrect, because it seems that when the navigation bar was hidden, the rest of the view took up empty space, and then the navigation bar was on top of the content. Is there anything I can do about this? Or am I approaching it incorrectly with push and pop? (Question No. 3).

Thanks!

+4
source share
2 answers

An interesting problem. You can try changing the hidden property in viewWillAppear and viewWillDisappear , but it seems that this will not produce the desired results either.

Can you imagine the view manager modally instead of making the navigation bar disappear? If this is the last view controller on the stack, that would be possible. It may also make more sense for the user to see the view controller presented in different ways. This may indicate to the user that the transition from this view controller is no longer performed using the back button. This might be wiser than just disappearing the navigation bar.

If you still want the view controller to shift to the right, I don’t think it can be done with a modal controller. But you can do this by animating the view that fills the screen. (You simply add a view with a frame that has origin.x equal to the width of the screen. Then in the animation you change origin.x to 0.0. Let me know if you need more details about this.)

However, I would recommend presenting the view controller in a different way, since the view is usually presented by the navigation controller. Since, in fact, you no longer allow the user to move away from this view, as usual, from the navigation controller. (So, my answer to question No. 3 will be yes.)

0
source

I ran into the same problem (only in the reverse order: I started with the NavigationBar being hidden and clicking on the view where I wanted the NavigationBar to be visible), and there really is a very simple fix.

Just replace your calls:

 [self.navigationController.navigationBar setHidden:NO]; 

with

 [[self navigationController] setNavigationBarHidden:NO animated:YES]; 

In my code, I call these instructions in the methods - (void)viewWillAppear:(BOOL)animated each corresponding view controller.

I just tried this solution in the order that you are using (visible, then hidden) and it seems to work just as well.

+1
source

Source: https://habr.com/ru/post/1379722/


All Articles