代码之家  ›  专栏  ›  技术社区  ›  Matt H

WKCrownDelegate似乎没有使用Xcode 9 GM

  •  5
  • Matt H  · 技术社区  · 7 年前

    我尝试了以下针对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 回复  |  直到 7 年前
        1
  •  5
  •   Larry Drebes    7 年前

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

        2
  •  1
  •   Gergely    4 年前

    正在添加 在里面 willActivate() 在Xcode10中没有帮助我。 crownSequencer。焦点() 都不在 或在 willActivate() 但是在 didAppear() . 因此,您需要添加以下行:

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