开发者

How does the search display controller hide the navigation bar?

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

How is this done? If you simply set the navigation bar to hidden or shown, it happens instantly. I can't figure out how it seems to be hidden just for one view controller in the stack!

Many thanks,

Michae开发者_开发百科l


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

If you need to do this on a per-view controller basis, just override the view controller's -viewDidAppear: and -viewWillDisappear: methods, e.g.:

- (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 pushed on top of the navigation stack, and show the navigation bar when the view controller is popped off.

You can call -setNavigationBarHidden:animated: whenever you want, but those two methods are useful for applying lots of UI changes.


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

it will not hide navigation bar.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜