如何让 Digital Crown 重新与 watchOS 4 配合使用

How to put the Digital Crown back to work with watchOS 4

我有一个 watchkit 应用程序,它通过设置

使用数字表冠
crownSequencer.delegate = self
crownSequencer.focus()

在我正在实现的界面控制器的唤醒方法中:

class InterfaceController: WKInterfaceController, WKCrownDelegate 

在 watchOS 3 中,我的委托方法执行得很好:

// called when the crown rotates, rotationalDelta is the change since the last call (sign indicates direction).
func crownDidRotate(_ crownSequencer: WKCrownSequencer?, rotationalDelta: Double) {

    // do something important here...
}

升级到 watchos4 后,此功能失效。 简单的重新编译和转换为 swift 4 没有帮助。

我可以通过简单地将 crownSequencer 代码移动到我的界面控制器的 willActivate 方法来解决这个问题:

override func willActivate() {
    ...

    crownSequencer.delegate = self
    crownSequencer.focus()
}

在我看来,如果您过早设置焦点,watchOS 4 中的某些内容会偷走焦点(可能与我正在使用的 spritekit 相关?)。

希望这能为其他人节省一些时间!