Skip to content

Instantly share code, notes, and snippets.

@victorchee
Last active October 18, 2017 06:43
Show Gist options
  • Save victorchee/1167b0205c62198778a6b79e2c642299 to your computer and use it in GitHub Desktop.
Save victorchee/1167b0205c62198778a6b79e2c642299 to your computer and use it in GitHub Desktop.
BOOL animating;
BOOL animationPending;
BOOL animationComplete;
- (void)rotateWithOptions:(UIViewAnimationOptions)options {
NSTimeInterval fullRotationInterval = 4.0;
[UIView animateWithDuration:fullRotationInterval/4.0 delay:0 options:options animations:^{
self.musicIconImageView.transform = CGAffineTransformRotate(self.musicIconImageView.transform, M_PI_2);
} completion:^(BOOL finished) {
if (animating) {
[self rotateWithOptions:UIViewAnimationOptionCurveLinear];
} else if (animationPending) {
animationPending = NO;
animating = YES;
[self rotateWithOptions:UIViewAnimationOptionBeginFromCurrentState];
} else if ((options & UIViewAnimationOptionCurveEaseOut) == 0) {
// Last spin
[self rotateWithOptions:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionCurveEaseOut];
} else {
animationComplete = NO;
}
}];
}
- (void)startRotation {
animationComplete = NO;
if (!animating) {
if (animationComplete) {
animationPending = YES;
} else {
animating = YES;
[self rotateWithOptions:UIViewAnimationOptionCurveEaseIn];
}
}
}
- (void)stopRotation {
animating = NO;
animationComplete = YES;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment