简体   繁体   English

如何创建基于页面的WatchKit应用?

[英]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()
        }
    }
  1. Am i doing it right using the reloadRootControllersWithNames method to create a page based application? 我使用reloadRootControllersWithNames方法创建基于页面的应用程序正确吗?
    • Where should I call this method? 我应该在哪里调用此方法?
    • Is there an entry point file like the AppDelegate for WatchKit other than the arrow in the storyboard? 除了情节提要中的箭头之外,是否还有诸如WatchKit的AppDelegate类的入口点文件?
    • Can I configure the paginated views in the storyboard itself without writing separate code? 是否可以在情节提要中本身配置分页视图而无需编写单独的代码?
  2. Right now my entire view is paginated. 现在我的整个观点已经分页了。 I just want the images to change, I don't want the button to move. 我只想更改图像,不希望按钮移动。 How can I accomplish this? 我该怎么做? http://www.apple.com/watch/films/#film-fitness Please check this video. http://www.apple.com/watch/films/#film-fitness请观看此视频。 I want the pagination they show here at 02:17. 我想要他们在02:17在这里显示的分页。
  3. Last thing is the animations they do. 最后是他们做的动画。 The animations they show for the texts and the exercise rings. 他们为文本和练习环显示的动画。 I'd be really thankful if anyone can give me an idea on how to do such animations. 如果有人能给我关于如何制作此类动画的想法,我将非常感谢。 :) :)

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM