SwiftUI animation rotation glitch @ 360/0 degree marker

Viewed 415

So I have a view that rotates according to a specific degree that is set by the direction the device is pointed in. The problem is when you go from 359.99 to 0.01 degree rotation (which is the smallest difference in actuality, the view chooses to rotate all the way from 360 down to 0, instead of just wrapping around. This causes problems with the animation because it makes the view spin 359 degrees back to the 0 position instead of just clicking into the 0 degree position from 359. I've tried setting animation to nil between 359-360 and 0-1 but if you move the device fast enough, you still see this bad animation. Any suggestions?

Image("arrow")
    .rotationEffect(Angle(degrees: deviceHeading))
    .animation(.easeOut)

https://youtu.be/MzpI6THHS8U

As you can see, right in that position, it rotates fully around instead of just doing a change of taking the short path to the new position.

0 Answers
Related