Search code examples
iosanimationrotationdirection

ios UIImageView rotation direction in swift at variable degree in clockwise direction


I am rotating image through this code

UIView.animate(withDuration: 2) {

        self.blueNeedleImageView.transform = CGAffineTransform(rotationAngle: CGFloat(myDegreeValue * Double.pi / 180))

    }

Problem is that it is rotating in shortest path. I want always clockwise rotation and rotation degree is variable. this and this does not provide a solution.


Solution

  • Just split it to two animations if the angle is more than 180°.