如何在一个屏幕上指定显示导航栏,而不是在另一个屏幕上显示它?

发布于 2025-01-27 16:47:52 字数 662 浏览 1 评论 0原文

我有两个ViewControllers,VCAvcbVCA是初始视图控制器,它嵌入了导航控制器中,navvc。显示vcb i PUST vcb带有navvc。 但是,对于VCA,我不想显示导航栏,对于vcb,我确实要显示导航栏。 我已经看过这答案但这并不能解决我的问题,因为我需要支持反对。当我试图使导航控制器在反向间管上消失时,导航控制器立即消失或慢慢消失,具体取决于启用动画。 我的navvc还提供了一个页面动画,因此,如果我将导航栏设置为消失在view> viewwilldisappear时,当我模仿pan时,它就会消失。

有没有办法指定第一个VC上没有导航栏并在第二个VC上显示的?还是有一些我不熟悉的更好方法?

I have two viewControllers, vcA and vcB.
vcA is the initial view controller and it's embedded in a navigation controller, navVC. To display vcB I push vcB with navVC.
However, for vcA I don't want to display the navigation bar and for vcB I do want to display the navigation bar.
I've seen this answer but it doesn't solve my problem because I need to support backswipe. When I try to cause the navigation controller to disappear on backswipe the navigation controller immediately disappears or slowly disappears depending on if animation is enabled.
My navVC is presenting with a page sheet animation as well so if I set the nav bar to disappear in viewWillDisappear it disappears as I modally pan down.

Is there a way to specify to not have a navigation bar shown on the first vc and have it shown on the second? Or is there some better way to do this I'm not familiar with?

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

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

发布评论

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

评论(2

心在旅行 2025-02-03 16:47:52

虽然默认视图控制器最初使生活变得非常美好,但它们通常以非常具体的方式运行,并试图在这些范式之外进行操作将是困难的,即使不是不可能。

我建议不要在您不希望栏出现的视图上使用默认的导航视图控制器,而是自定义自己的视图来支持您要复制的确切行为。

例如,您可以使用常规视图,而无需在Viewa顶部使用栏,然后将其转换为导航视图控制器,并使视图B的默认视图。

While the default view controllers make life really great initially, they usually come with very specific ways they operate and trying to operate outside those paradigms will be difficult if not impossible.

I would suggest not using the default navigation view controller on the view that you don’t want the bar to appear on and instead customize your own view to support the exact behavior you’re trying to replicate.

For example you can use a regular view without a bar at the top for viewA and then segue to the navigation view controller and make view B its default view.

沙与沫 2025-02-03 16:47:52

您为什么要在VCA上隐藏导航栏?

取而代之的是,您可以使BartintColor与VCA背景颜色相同,您不必隐藏导航栏。

if #available(iOS 15.0, *) {
   let appearance = UINavigationBarAppearance()
   appearance.configureWithOpaqueBackground()
   appearance.backgroundColor = color
   vcA.navigationController?.navigationBar.standardAppearance = appearance
   vcA.navigationController?.navigationBar.scrollEdgeAppearance = vcA.navigationController?.navigationBar.standardAppearance
} else {
   vcA.navigationController?.navigationBar.barTintColor = color
}

Why do you want to hide the navigation bar on vcA ?

Instead you can just make the barTintColor same as the vcA background color , you need not have to hide the navigation bar.

if #available(iOS 15.0, *) {
   let appearance = UINavigationBarAppearance()
   appearance.configureWithOpaqueBackground()
   appearance.backgroundColor = color
   vcA.navigationController?.navigationBar.standardAppearance = appearance
   vcA.navigationController?.navigationBar.scrollEdgeAppearance = vcA.navigationController?.navigationBar.standardAppearance
} else {
   vcA.navigationController?.navigationBar.barTintColor = color
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文