WKCrownDelegate似乎没有使用Xcode 9 GM

时间:2017-09-16 01:50:29

标签: xcode watch-os

我尝试过针对iOS 10.0 / Watch OS 3.0和iOS 11.0 / Watch OS 4.0的以下代码,并在模拟器和Watch OS 4设备上进行了测试。似乎什么都没有触发crownDidRotate委托方法。

简单的界面,一个标签连接到插座。我知道它已连接,因为我更改了awake方法中的文本。当旋转表冠时,断开委托方法永远不会停止。

有什么想法吗?

import Foundation
import WatchKit
class InterfaceController: WKInterfaceController, WKCrownDelegate {
    var value = 1
    @IBOutlet var label: WKInterfaceLabel!
    override func awake(withContext context: Any?) {
        super.awake(withContext: context)
        label.setText("Yeah?")
        crownSequencer.delegate = self
        crownSequencer.focus()
    }
    func crownDidRotate(_ crownSequencer: WKCrownSequencer?, rotationalDelta: Double) {
        label.setText("Rotational: \(rotationalDelta)")
    }
}

2 个答案:

答案 0 :(得分:4)

我有同样的经历。作为一个黑客,我在willActivate()中添加了另一个对crownSequencer.focus()的调用,现在我正在看事件。 (xcode 9.0 gm,ios 11.0 gm,watchos 4.0 gm)

答案 1 :(得分:0)

willActivate()中添加 crownSequencer.focus()对Xcode10没有帮助。 您既不必在 awake() willActivate()中也可以在 中调用 crownSequencer.focus() > didAppear() 。因此,您需要添加以下几行:

override func didAppear() {
    super.didAppear()
    crownSequencer.focus()
}