0

How to get a smooth infinite rotation animation with a non-symmetrical image? I get a very brief pause between each rotation. I tried using other CalculationMode but with no luck. Has anybody any idea?

imageToRotate.hidden = false

let duration = 0.5
let delay = 0.0
let options = UIViewKeyframeAnimationOptions.CalculationModePaced | UIViewKeyframeAnimationOptions.Repeat

let fullRotation = CGFloat(M_PI * 2)

UIView.animateKeyframesWithDuration(duration, delay: delay, options: options, animations: {
    UIView.addKeyframeWithRelativeStartTime(0, relativeDuration: 0, animations: {
        self.imageToRotate.transform = CGAffineTransformMakeRotation(1/3 * fullRotation)
    })

    UIView.addKeyframeWithRelativeStartTime(0, relativeDuration: 0, animations: {
        self.imageToRotate.transform = CGAffineTransformMakeRotation(2/3 * fullRotation)
    })

    UIView.addKeyframeWithRelativeStartTime(0, relativeDuration: 0, animations: {
        self.imageToRotate.transform = CGAffineTransformMakeRotation(3/3 * fullRotation)
    })


    }, completion: {finished in


})

edit: I tried the approach suggested in the "possible duplicate" but unfortunately as @levigroke says with a non-symmetrical image I get a "snap" back to the original orientation after 90 degrees. He also says "One of these less elegant solutions, seen below, will truly rotate the image, but there may be a noticeable stutter when the animation is restarted". That's my initial problem so I feel that his answer won't do in my case.

pinolo
  • 347
  • 2
  • 7
  • 20
  • Your code makes no sense. How can all the keyframes start at time 0 and have duration 0? That's nuts. – matt Dec 15 '14 at 04:26
  • I've read that "CalculationModePaced as an option which ignores any values you’ve entered for relativeStartTime and relativeDuration and automatically figures out correct values for a consistent animation". Hence the zeroes. Is that wrong? – pinolo Dec 15 '14 at 04:41

0 Answers0