搜索显示控制器如何隐藏导航栏?

发布于 2024-08-11 19:57:29 字数 189 浏览 10 评论 0原文

当您输入由搜索显示控制器处理的搜索栏时,它会向上滑动视图并向上推动导航栏。这很容易做到,但是,当您单击搜索结果并将新视图推送到导航控制器的堆栈上时,导航栏会随视图从右侧滑入!

这是怎么做到的?如果您只需将导航栏设置为隐藏或显示,它就会立即发生。我不明白它是如何仅针对堆栈中的一个视图控制器隐藏的!

非常感谢,

迈克尔

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,

Michael

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

生生不灭 2024-08-18 19:57:29

您可以为导航栏的过渡设置动画。请参阅 -setNavigationBarHidden:animated: 了解更多详细信息。

如果您需要在每个视图控制器的基础上执行此操作,只需覆盖视图控制器的 -viewDidAppear:-viewWillDisappear: 方法,例如:

- (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];
}

上面将隐藏导航当此视图控制器被推到导航堆栈顶部时显示导航栏,并在弹出视图控制器时显示导航栏。

您可以随时调用 -setNavigationBarHidden:animated:,但这两个方法对于应用大量 UI 更改非常有用。

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.

笑忘罢 2024-08-18 19:57:29
-(void)viewDidLayoutSubviews{
    [self.navigationController setNavigationBarHidden:NO animated:NO];
}

它不会隐藏导航栏。

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

it will not hide navigation bar.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文