swiftwatchkitapple-watchwatchos-3

Increment / Decrement value on Digital Crown rotation


I am able to get the events for the digital crown and I want to decrease the speed as on rotating a little crown calls multiple events. So, I want to achieve if there is about 30 degrees rotation in any direction I will increase or decrease the value. How can I do that?

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

Solution

  • To achieve expected result in watchOS, you need to manage extra variable that tell us about Digital Crown rotated at some specific angle like,

    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 
         }
    }