gpt4 book ai didi

ios - 用于 Force Touch/Digital Crown 的 WatchKit API?

转载 作者:IT王子 更新时间:2023-10-29 07:55:30 26 4
gpt4 key购买 nike

我对 Apple Watch 引入的新用户交互可能性感到非常兴奋,其中包括 Force Touch 和 Digital Crown。

但是,我无法在 WatchKit API 中找到对它们的提及。有什么方法可以从 Force Touch/Digital Crown 接收事件吗?是否可以为事件设置自定义处理程序?

最佳答案

watchOS 3 添加了 WKCrownSequencerWKCrownDelegate报告数字表冠的状态(例如转速),以及在用户旋转表冠时接收通知。

您可以使用皇冠音序器提供通用输入来控制场景或界面对象。

Apple 已更新其 WatchKit Catalog sample code包括一个 WKInterfaceController 表冠音序器示例,演示如何使用 Apple Watch 数字表冠与其他对象交互:

class CrownDetailController: WKInterfaceController, WKCrownDelegate {
@IBOutlet var velocityLabel: WKInterfaceLabel!
@IBOutlet var stateLabel: WKInterfaceLabel!
@IBOutlet var pickerView: WKInterfacePicker!

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

let itemList: [(String, String)] = [
("Item 1", "Red"),
("Item 2", "Green"),
("Item 3", "Blue")
]
let pickerItems: [WKPickerItem] = itemList.map {
let pickerItem = WKPickerItem()
pickerItem.caption = $0.0
pickerItem.title = $0.1
return pickerItem
}
pickerView.setItems(pickerItems)

crownSequencer.delegate = self
}

override func willActivate() {
// This method is called when watch view controller is about to be visible to user
super.willActivate()
crownSequencer.focus()
}

@IBAction func focusCrown(sender: AnyObject) {
crownSequencer.focus()
}

func updateCrownLabels() {
velocityLabel.setText(String(format: "RPS: %2.2lf", crownSequencer.rotationsPerSecond))
stateLabel.setText(crownSequencer.isIdle ? "Idle: true" : "Idle: false")
}

func crownDidBecomeIdle(_ crownSequencer: WKCrownSequencer?) {
updateCrownLabels()
}

func crownDidRotate(_ crownSequencer: WKCrownSequencer?, rotationalDelta: Double) {
updateCrownLabels()
}

}

关于ios - 用于 Force Touch/Digital Crown 的 WatchKit API?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27077887/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com