[英]Is page-based navigation possible in a SwiftUI app on WatchOS?
Yes, this is possible.是的,这是可能的。 First, define hosting controllers for each of your pages like so
首先,像这样为每个页面定义托管控制器
class Page1HostingController: WKHostingController<Page1View> {
override var body: Page1View {
self.setTitle("page1")
return Page1View()
}
}
class Page2HostingController: WKHostingController<Page2View> {
override var body: Page2View {
self.setTitle("page2")
return Page2View()
}
}
where Page1View
and Page2View
are your SwiftUI implementations.其中
Page1View
和Page2View
是您的 SwiftUI 实现。
Then, add new view controllers to your Interface.storyboard
, set their implementation classes to your new controller classes and connect them via a "next page" segue.然后,将新的视图控制器添加到您的
Interface.storyboard
,将它们的实现类设置为您的新控制器类并通过“下一页”segue 连接它们。
If you are using the new SwiftUI App Lifecycle and can't access Storyboards (or just need a solution for App Delegate Cycle without using Storyboards), you can use the new Page View style in SwiftUI 2:如果您正在使用新的 SwiftUI App Lifecycle 并且无法访问 Storyboards(或者只需要 App Delegate Cycle 的解决方案而不使用 Storyboards),您可以使用 SwiftUI 2 中的新页面视图样式:
WindowGroup {
TabView {
Page1View()
Page2View()
}
.tabViewStyle(PageTabViewStyle())
}
There is NavigationLink button which triggers a navigation presentation when pressed.有NavigationLink按钮,按下时会触发导航演示。
var body: some View {
VStack() {
NavigationLink(destination: Text("Destination view"), label: {
Text("Title of the NavigationLink button")
})
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.