简体   繁体   English

如何创建共享导航栏以在 SwiftUI 中的多个视图之间进行交互导航?

[英]How to create a shared navigation bar to inter-navigate among multiple views in SwiftUI?

I would like to navigate among screens A, B, and C by tapping the corresponding button in a shared navigation bar at the bottom of every screen.我想通过点击每个屏幕底部共享导航栏中的相应按钮在屏幕 A、B 和 C 之间导航。 How can I create such a toolbar to achieve this inter-navigability among screens?如何创建这样的工具栏来实现屏幕之间的这种可导航性?

在此处输入图像描述 在此处输入图像描述 在此处输入图像描述

You would use a TabView {...} to accomplish this.您将使用TabView {...}来完成此操作。 Effectively you instantiate your views inside of the TabView then add an item modifier to each view.实际上,您在TabView内实例化您的视图,然后为每个视图添加一个项目修饰符。

var body: some View {
    TabView {
        Text("A")
            .tabItem { Text("A") }
        Text("B")
            .tabItem { Text("B") }
        Text("C")
            .tabItem { Text("C") }
    }
}

What this code does: https://i.stack.imgur.com/CKBHm.gif此代码的作用: https://i.stack.imgur.com/CKBHm.gif

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM