SwiftUIでの画面遷移4
NavigationLinkで遷移先を複数にするとどうなるかです。
親Viewでのコード
import SwiftUI
struct ContentView: View {
var body: some View {
VStack {
NavigationView {
NavigationLink(destination: SecondView()) {
Text("二つ目画面")
.frame(height: 50)
}
}
NavigationView {
NavigationLink(destination: ThirdView()) {
Text("三つ目画面")
.frame(height: 50)
}
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
子View1
import SwiftUI
struct SecondView: View {
var body: some View {
GeometryReader { geometory in
VStack {
Text("二画面目")
}
.frame(width: geometory.size.width,
height: geometory.size.height)
.background(Color.cyan)
}
}
}
struct SecondView_Previews: PreviewProvider {
static var previews: some View {
SecondView()
}
}
子View2
import SwiftUI
struct ThirdView: View {
var body: some View {
GeometryReader { geometory in
VStack {
Text("三画面目")
}
.frame(width: geometory.size.width,
height: geometory.size.height)
.background(Color.blue)
.foregroundColor(Color.white)
}
}
}
struct ThirdView_Previews: PreviewProvider {
static var previews: some View {
ThirdView()
}
}
コメント