ios - 如何创建基于页面的 WatchKit 应用程序?

标签 ios objective-c swift pagination watchkit

我正在尝试创建一个基于页面的 WatchKit 应用。当应用程序加载时,我想要一个包含图像的页面和分页 View 中的按钮,并且滑动应该在图像数组之间切换。

Home View

https://www.dropbox.com/s/yn3tstngx8h94xo/iOS%20Simulator%20Screen%20Shot%20-%20Apple%20Watch%2009-Mar-2015%203.28.01%20am.png?dl=0

我尝试了WKInterfaceController.reloadRootControllersWithNames(["home", "home", "home", "home", "home"], contexts: ["1", "2", "3", "4", "5"]) 其中 home 是 InterfaceController 的标识符。我从另一个 InterfaceController (初始界面 Controller )调用此方法。我获得基于页面的 View ,但初始 View 是空白的。

    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. 我使用 reloadRootControllersWithNames 方法创建基于页面的应用程序是否正确?
    • 我应该在哪里调用这个方法?
    • 除了 Storyboard 中的箭头之外,是否还有类似于 WatchKit 的 AppDelegate 的入口点文件?
    • 我可以在 Storyboard本身中配置分页 View 而无需编写单独的代码吗?
  2. 现在我的整个 View 已分页。我只想改变图像,我不想让按钮移动。我怎样才能做到这一点? http://www.apple.com/watch/films/#film-fitness请查看这个视频。我想要他们在 02:17 显示的分页。
  3. 最后一件事是他们所做的动画。他们为文本和练习环显示的动画。如果有人能给我关于如何制作此类动画的想法,我将非常感激。 :)

最佳答案

仅回答问题 1:

我使用几乎完全相同的技术创建了一个基于页面的应用程序,除了我调用了 WKInterfaceController.reloadRootControllersWithNames() 来自 willActivate() 函数,而不是 awakeWithContext() 函数。不确定这是否重要。

我假设“home”是不同 WKInterfaceController 的标识符?如果您尝试使用起始界面 Controller 作为分页界面 Controller ,我认为它不会正常工作。所以这可能是您问题的根源。

但是,仅当页面数量可变时才需要这种以编程方式指定页面的方法。如果您在构建时知道页面布局,则可以将它们全部布局在 Storyboard中,然后按住 Control 键并从一个到另一个拖动,选择“下一页”关系。

如果您使用 Storyboard 来完成此操作,则可以将起始界面 Controller 作为页面的第一个页面,然后如果您愿意,后续界面 Controller 可以使用相同的类。

关于ios - 如何创建基于页面的 WatchKit 应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28932776/

相关文章:

ios - 将包含 Latex Command for Mathematical 公式的 HTML 文本转换为输出正确公式的纯文本或属性文本

ios - 导航栏后退按钮只能使用一次

swift - 如何从完整字符串 iOS swift 中为字符串查找多个 NSRange

objective-c - 您可以将 FBSnapshottestcase 库与 Swift 一起使用吗?

ios - 在 UILabel 上显示 iPhone 剪切复制粘贴菜单

ios - 通过重写 TabbarViewController 中的 shouldSelect 方法来推送 View Controller

ios动画一一

iphone - 将 iPad 2 中的相机锁定为横向模式

iphone - 自定义 UIView 的文本选择和放大镜实现

swift - 无法建立 CKRecord 变量 - 准备继续