sprite-kit - watchOS 3.0 在 SpriteKit 中检测表冠旋转

标签 sprite-kit watchkit swift3 xcode8 watchos-3

因此,从 watchOS 3.0 开始,您现在可以获得数字表冠的旋转。我设法使用了crownDidRotate InterfaceController 中的函数。
但我无法从 SKScene 类中旋转表冠。
有人可以帮我解决这个问题吗?我现在很迷茫?
谢谢。

最佳答案

得到那些crownDidRotate在你的接口(interface) Controller 中调用,你必须采用 WKCrownDelegate 接口(interface) Controller 中的协议(protocol),并将您的接口(interface) Controller 设置为 delegate crownSequencer .

获取 crownDidRotate调用其他类,采用 WKCrownDelegate 该类中的协议(protocol),并将该类的实例设置为 delegate 您的接口(interface) Controller 的crownSequencer .

大概你已经有一些这样的代码来设置你的 SpriteKit 场景:

class InterfaceController: WKInterfaceController {

    @IBOutlet var spriteGizmo: WKInterfaceSKScene!

    override func awake(withContext context: AnyObject?) {
        super.awake(withContext: context)

        let scene = MyScene(fileNamed: "MyScene")
        spriteGizmo.presentScene(MyScene(fileNamed: "MyScene"))
    }
}

如果您已声明 WKCrownDelegate 符合您的MyScene类,只需添加一行将其设置为接口(interface) Controller 的冠序列器的委托(delegate):
let scene = MyScene(fileNamed: "MyScene")
spriteGizmo.presentScene(MyScene(fileNamed: "MyScene"))
crownSequencer.delegate = scene

(或者,您可以在 Storyboard 中设置 WKInterfaceSKScene 的场景。在这种情况下,您仍然可以使用 WKInterfaceSKScene 从界面 Controller 引用 IBOutlet。然后在 awake(withContext:) 中,您可以访问场景通过该导出并将其设置为皇冠代表。)

关于sprite-kit - watchOS 3.0 在 SpriteKit 中检测表冠旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37815563/

相关文章:

ios - 如何在 cgmutablepath 中设置形状的颜色?

ios - 如何使用 alpha 值在 CALayer() 上添加颜色?

ios - 如何为我现有的 Xcode 项目添加复杂功能?

ios - 如何快速存储落针目的地坐标

swift - SKAction.playSoundFileNamed() 导致高内存崩溃

swift - 如何检测我触摸了哪些 Sprite

swift - iPhone 和 Watch 之间共享数据的 App Group 孤儿功能

swift - 从像素数据重建图像

ios - 如何使用 Swift 修复 iOS 应用程序上的 fatal error ?