在不同的视图中使用SwiftUI可以通过以下几种方式实现:
NavigationView {
List {
NavigationLink(destination: DetailView()) {
Text("Go to Detail View")
}
}
}
TabView {
Text("Tab 1")
.tabItem {
Image(systemName: "1.circle")
Text("Tab 1")
}
Text("Tab 2")
.tabItem {
Image(systemName: "2.circle")
Text("Tab 2")
}
}
struct ContentView: View {
@State private var isShowingSheet = false
var body: some View {
Button("Show Sheet") {
isShowingSheet = true
}
.sheet(isPresented: $isShowingSheet) {
SheetView()
}
}
}
struct ContentView: View {
@State private var isShowingView1 = true
var body: some View {
ZStack {
if isShowingView1 {
View1()
} else {
View2()
}
}
}
}
这些只是使用SwiftUI在不同的视图中进行切换的一些常见方法,实际上还有很多其他的方式可以实现。根据具体的需求和场景,你可以选择适合的方法来实现不同视图之间的切换。
领取专属 10元无门槛券
手把手带您无忧上云