[英]How to create a page based WatchKit app?
I'm trying to create a page based WatchKit app . 我正在尝试创建一个基于页面的WatchKit应用程序 。 When the app loads I want a page with an image and a button in a paginated view and swiping should switch between an array of images.
当应用程序加载时,我希望在页面上以分页视图显示带有图像和按钮的页面,并且滑动应在图像数组之间切换。
https://www.dropbox.com/s/yn3tstngx8h94xo/iOS%20Simulator%20Screen%20Shot%20-%20Apple%20Watch%2009-Mar-2015%203.28.01%20am.png?dl=0 https://www.dropbox.com/s/yn3tstngx8h94xo/iOS%20Simulator%20Screen%20Shot%20-%20Apple%20Watch%2009-Mar-2015%203.28.01%20am.png?dl=0
I tried WKInterfaceController.reloadRootControllersWithNames(["home", "home", "home", "home", "home"], contexts: ["1", "2", "3", "4", "5"])
where home
is the identifier of the InterfaceController. 我尝试了
WKInterfaceController.reloadRootControllersWithNames(["home", "home", "home", "home", "home"], contexts: ["1", "2", "3", "4", "5"])
,其中home
是InterfaceController的标识符。 I'm calling this method from another InterfaceController which is the initial interface controller. 我正在从另一个InterfaceController调用此方法,InterfaceController是初始接口控制器。 I get the page based views but the initial view is blank.
我得到基于页面的视图,但初始视图为空白。
import WatchKit
import Foundation
class InterfaceController: WKInterfaceController {
override func awakeWithContext(context: AnyObject?) {
super.awakeWithContext(context)
WKInterfaceController.reloadRootControllersWithNames(["home", "home", "home", "home", "home"], contexts: ["1", "2", "3", "4", "5"])
}
override func willActivate() {
// This method is called when watch view controller is about to be visible to user
super.willActivate()
}
override func didDeactivate() {
// This method is called when watch view controller is no longer visible
super.didDeactivate()
}
}
reloadRootControllersWithNames
method to create a page based application? reloadRootControllersWithNames
方法创建基于页面的应用程序正确吗?
AppDelegate
for WatchKit other than the arrow in the storyboard? AppDelegate
类的入口点文件? Answering question 1 only: 仅回答问题1:
I created a page-based app using almost exactly the technique you used here, except that I called WKInterfaceController.reloadRootControllersWithNames() from the willActivate() function, not the awakeWithContext() function. 我几乎使用了您在此使用的技术创建了一个基于页面的应用程序,只是我从willActivate()函数(而不是awakeWithContext()函数)调用了WKInterfaceController.reloadRootControllersWithNames()。 Not sure if this is important.
不知道这是否重要。
I am assuming that "home" is the identifier for a different WKInterfaceController? 我假设“ home”是另一个WKInterfaceController的标识符? I do not think it will work correctly if you try to use the starting interface controller as the paged interface controller.
我认为如果尝试将启动接口控制器用作页面接口控制器,它将无法正常工作。 So that could be the source of your problem.
因此,这可能是问题的根源。
However this method of specifying pages programmatically is only needed if you have a variable number of pages. 但是,仅当您的页面数可变时,才需要使用这种以编程方式指定页面的方法。 If you know your page layout at build time, you can lay them all out in your storyboard, then Control-drag from one too the other, choosing the "Next page" relationship.
如果您在构建时就知道页面布局,则可以将它们全部放在情节提要中,然后按住Control键并拖动另一个,选择“下一页”关系。
If you do it using the storyboard, you can have the starting interface controller as the first of the pages, and then subsequent interface controllers can use the same class if you want them to. 如果使用情节提要板进行操作,则可以将启动界面控制器作为页面的第一页,然后,如果需要,后续界面控制器可以使用相同的类。
#2和#3的答案很简单:您不能,至少在当前版本的WatchKit中不能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.