gpt4 book ai didi

swift - 数字表冠旋转的增量/减量值

转载 作者:可可西里 更新时间:2023-11-01 01:21:58 24 4
gpt4 key购买 nike

我能够获得数字表冠的事件,我想降低速度,因为旋转一个小表冠会调用多个事件。所以,我想实现如果在任何方向上有大约 30 度的旋转,我将增加或减少该值。我该怎么做?

func crownDidRotate(_ crownSequencer: WKCrownSequencer?, rotationalDelta: Double) {
if value > 0 {
myValue = myValue + 1
} else if value < 0 {
myValue = myValue - 1
}
}

最佳答案

要在 watchOS 中实现预期结果,您需要管理额外的变量,这些变量会告诉我们有关以某个特定角度旋转的数码表冠,例如,

let expectedMoveDelta = 0.523599 //Here, current delta value = 30° Degree, Set delta value according requirement.
var crownRotationalDelta = 0.0

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

crownRotationalDelta += rotationalDelta
if crownRotationalDelta > expectedMoveDelta { //Crown rotating in clock-wise direction
myValue = myValue + 1
crownRotationalDelta = 0.0
} else if crownRotationalDelta < -expectedMoveDelta { //Crown rotating in anti clock-wise direction
myValue = myValue - 1
crownRotationalDelta = 0.0
}
}

关于swift - 数字表冠旋转的增量/减量值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43384077/

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