[英]SwiftUI and NavigationBar
I have a large iOS app with swift and XIBs for the view controllers.我有一个大型 iOS 应用程序,其中包含 swift 和用于视图控制器的 XIB。 Now I'm progressively migrating from XIBs/View controllers to SwiftUI but I don't know how to solve a specific problem.现在我正在逐步从 XIBs/View 控制器迁移到 SwiftUI 但我不知道如何解决特定问题。
Some XIB/View controllers have a navigation bar, if these XIB/controllers push a SwiftUI view the SwiftUI view appears correctly with its content and the navigation bar inherited from its parent XIB view.一些 XIB/View 控制器有一个导航栏,如果这些 XIB/控制器推送 SwiftUI 视图,SwiftUI 视图会正确显示其内容,并且导航栏继承自其父 XIB 视图。 But some of the SwiftUI views need to change some of the inherited navigation bar buttons and I don't know how to access from the SwiftUI code to the navigation bar content.但是SwiftUI的一些视图需要更改一些继承的导航栏按钮,我不知道如何从SwiftUI代码访问导航栏内容。
I tried to hide the inherited navigation bar using我试图使用隐藏继承的导航栏
.navigationBarTitle("")
.navigationBarHidden(true)
(which is working) and creating a SwiftUI navigationbar using NavigationView component, but: (正在运行)并使用 NavigationView 组件创建一个 SwiftUI 导航栏,但是:
I don't know if this is the correct approach.我不知道这是否是正确的方法。
Using this NavigationView component the new navigation bar shown is much higher than the inherited navigation bar.使用此 NavigationView 组件,显示的新导航栏比继承的导航栏高得多。 Why is it showing a much higher navbar?为什么它显示更高的导航栏? Could I change this heght and how?我可以改变这个高度吗?如何改变?
Thank you!谢谢!
Well, I've just discovered that I have this method:好吧,我刚刚发现我有这个方法:
.navigationBarItems(leading: View, trailing: View)
So I can customize my navbar buttons with it.所以我可以用它自定义我的导航栏按钮。 I don't need to hide the inherited navbar, just customize it.我不需要隐藏继承的导航栏,只需自定义它即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.