数字表冠旋转的增量/减量值
Increment / Decrement value on Digital Crown rotation
我能够获得数字表冠的事件,我想降低速度,因为旋转一个小表冠会调用多个事件。所以,我想实现如果在任何方向上有大约 30 度的旋转,我将增加或减少该值。我该怎么做?
func crownDidRotate(_ crownSequencer: WKCrownSequencer?, rotationalDelta: Double) {
if value > 0 {
myValue = myValue + 1
} else if value < 0 {
myValue = myValue - 1
}
}
要在 watchOS 中获得预期结果,您需要管理额外的变量,这些变量会告诉我们 Digital Crown 以某个特定角度旋转,例如,
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
}
}
我能够获得数字表冠的事件,我想降低速度,因为旋转一个小表冠会调用多个事件。所以,我想实现如果在任何方向上有大约 30 度的旋转,我将增加或减少该值。我该怎么做?
func crownDidRotate(_ crownSequencer: WKCrownSequencer?, rotationalDelta: Double) {
if value > 0 {
myValue = myValue + 1
} else if value < 0 {
myValue = myValue - 1
}
}
要在 watchOS 中获得预期结果,您需要管理额外的变量,这些变量会告诉我们 Digital Crown 以某个特定角度旋转,例如,
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
}
}