简体   繁体   中英

How to create a page based WatchKit app?

I'm trying to create a page based WatchKit app . 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

I tried WKInterfaceController.reloadRootControllersWithNames(["home", "home", "home", "home", "home"], contexts: ["1", "2", "3", "4", "5"]) where home is the identifier of the InterfaceController. I'm calling this method from another InterfaceController which is the initial interface controller. 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?
    • Where should I call this method?
    • Is there an entry point file like the AppDelegate for WatchKit other than the arrow in the storyboard?
    • 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. I want the pagination they show here at 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:

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. Not sure if this is important.

I am assuming that "home" is the identifier for a different 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.

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中不能。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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