无法在SwiftUI,WatchOS上使用TabView [英] Cannot use TabView on SwiftUI, WatchOS
问题描述
是否有一种方法可以在WatchOS上使用SwiftUI使用TabView?
Is there a way to use TabView using SwiftUI on WatchOS?
我已经看过大多数WWDC的谈话,他们没有在WatchOS上提及它.此外,在苹果文档中,SDK并未对此进行枚举.
I've seen most of the WWDC talks and they don't mention it for WatchOS. Moreover, in the apple documentation it is not enumerated under SDK's.
每当我尝试将其添加到WatchOS项目时,都会出现以下错误:
Whenever I try to add it to a WatchOS project I get the following error:
'TabView' is unavailable in watchOS
或者有没有很好的方法来复制所需的TabView?
Or is there a good way to replicate the desired TabView ?
我想要类似的东西: 只需水平滑动即可更改两个不同的页面.
I want something similar to this: Two different pages that are changed simply by swiping horizontally.
推荐答案
如果您想在应用中使用基于页面的导航(在视图控制器之间向左/向右滑动),只需在项目的故事板上添加另一个WKHostingController即可.通过在两个主机控制器之间创建序列来连接它们.顺序决定了您如何在控制器之间导航.
If you want a page based navigation (swipe left/right between view controllers) in your app you simply add another WKHostingController to your project's storyboard. Connect the two hosting controllers by creating a segue between them. The segue is what determines how you navigate between controllers.
此页面提供了有关如何执行操作的良好指南: https://www. techotopia.com/index.php/A_WatchKit_Page-based_Navigation_Tutorial
This page has a good guide on how to do it: https://www.techotopia.com/index.php/A_WatchKit_Page-based_Navigation_Tutorial
请记住,您要向情节提要中添加另一个托管控制器,而不要添加其他任何内容.
Just keep in mind that you want to add another hosting controller to the storyboard, not anything else.
我还没有找到在SwiftUI中以编程方式执行此操作的方法,这似乎是目前唯一的方法.
I have not found a way to do this programmatically in SwiftUI, this seems like the only way to do it for now.
这篇关于无法在SwiftUI,WatchOS上使用TabView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!