简体   繁体   English

如何在 SwiftUI Apple Watch App 中从一个屏幕导航到另一个屏幕

[英]How to navigate from one screen to another in SwiftUI Apple Watch App

I'm having problems doing navigation in a SwiftUI Apple Watch app.我在 SwiftUI Apple Watch 应用程序中进行导航时遇到问题。 There's minimal resources online regarding this.网上关于这方面的资源很少。

I mostly understand how to create SwiftUI views, but I'm not sure what the best way to navigate from SwiftUI view to another SwiftUI view is.我主要了解如何创建 SwiftUI 视图,但我不确定从 SwiftUI 视图导航到另一个 SwiftUI 视图的最佳方式是什么。

Is there a way to push a user to another SwiftUI screen when they tap a button?有没有办法在用户点击按钮时将用户推送到另一个 SwiftUI 屏幕?

To provide a very basic example how it can work on watchOS.提供一个非常基本的示例,它如何在 watchOS 上工作。

struct ListView: View {
var body: some View {



    List{

        RowView(title: "Row 1")
        RowView(title: "Row 2")
        RowView(title: "Row 3")
        RowView(title: "Row 4")

    }
    .listStyle(.carousel)


    }
}
struct RowView: View {
    let title: String
    var body: some View {

    NavigationLink(destination: Text("Detail \(title)")) {

        Text(title)
            .frame(height: 80, alignment: .topTrailing)
            .listRowBackground(
                Color.blue
                    .cornerRadius(12)
        )
    }
}

} }

You can do this by initializing a NavigationLink with your destination view.您可以通过使用目标视图初始化NavigationLink来实现此目的。 Its documentation is minimal at the moment, but the tutorial Building Lists and Navigation and WWDC session SwiftUI on watchOS may be of help.目前它的文档很少,但watchOS 上的教程构建列表和导航以及WWDC 会话 SwiftUI可能会有所帮助。

Just replace NavigationView by List, and it works like a charm只需将 NavigationView 替换为 List,它就像一个魅力

struct ContentView : View{
    var body : some View {
        List{
            VStack{
        NavigationLink(destination: BPView()) {
            Text("Some text")
                .foregroundColor(Color.blue);
        }
            NavigationLink(destination:myView()) {
                Text("Show text here")
                .foregroundColor(Color.blue);
            }
            }}

    }
}

暂无
暂无

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

相关问题 如何使用 SwiftUI 从登录屏幕导航到另一个屏幕 - How do I navigate to another screen from a login screen with SwiftUI 导航到 swiftUI 中的另一个屏幕 - Navigate to another screen in swiftUI 如何在 React Native 中从一个屏幕导航到另一个屏幕? - How to navigate from one screen to another in React native? 如何在 MVVM 中快速从一个屏幕导航到另一个屏幕 - How to Navigate from one screen to another in swift Working in MVVM 如何在不按动颤动的情况下从一个屏幕导航到另一个屏幕? - How to navigate from one screen to another without onpressed in flutter? 如何在三元渲染中从一个屏幕导航到另一个屏幕 - How navigate from a screen to another in ternary render 如何从功能组件导航到另一个屏幕? - How to navigate to another screen from a function component? 为 SwiftUI Apple Watch 应用实现基于页面的导航 - Implementing Page Based Navigation for SwiftUI Apple Watch App 我想从一个屏幕导航到另一个屏幕,但我有 undefined is not an object (评估'this.props.navigation.navigate') - I want to navigate from one screen to another screen but I am having undefined is not an object (evaluating 'this.props.navigation.navigate') 当用户单击工具提示的“完成”按钮时,如何使用“react-native-copilot”从一个屏幕导航到另一个屏幕 - How to use "react-native-copilot" to navigate from one screen to another, when user clicks on "Finish" button of tooltip
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM