How does the search display controller hide the navigation bar?

When you enter the search bar processed by the search display controller, it moves the view up and pushes the navigation bar up. This is easy enough to do, however, when you click on the search result and a new view is pushed onto the navigation system controller stack, the navigation bar slides to the right with the view!

How it's done? If you simply set the navigation bar to hidden or shown, this will happen instantly. I can’t understand how it is hidden for only one view controller on the stack!

Many thanks,

Michael

+3
source share
2 answers

You can animate the transition to the navigation bar. See more details -setNavigationBarHidden:animated:.

If you need to do this based on each controller, simply override the management -viewDidAppear:and -viewWillDisappear:view controller methods , for example:

- (void) viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:YES];
}

- (void) viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:YES];
}

The above will hide the navigation bar when this view controller is placed on top of the navigation stack, and show the navigation bar when the view controller pops up.

You can call -setNavigationBarHidden:animated:whenever you want, but these two methods are useful for applying a large number of user interface changes.

+8
source
-(void)viewDidLayoutSubviews{
    [self.navigationController setNavigationBarHidden:NO animated:NO];
}

it will not hide the navigation bar.

0
source

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


All Articles