IOS开发学习-Navigator跳转

80 阅读1分钟

一直不知道iOS页面跳转是怎么实现的,今天迈出第一步

基础代码

import SwiftUI

@main
struct NavigatorApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}
import SwiftUI

struct ContentView: View {
    @State var goNav = false
    
    var body: some View {
        NavigationView {
            VStack{
                NavigationLink(isActive: $goNav, destination: {
                    MapView()
                }, label: {
                    Text("点击跳转")
                })
                               
               Button {
                       goNav = true
                  } label: {
                      Text("导航跳转")
                  }
               }.navigationTitle("Navigator Title")
                .padding()
         }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
import SwiftUI

struct MapView: View {
    var body: some View {
        Text("Hello, map!")
    }
}

struct MapView_Previews: PreviewProvider {
    static var previews: some View {
        MapView()
    }
}