Last active
October 18, 2017 06:43
-
-
Save victorchee/1167b0205c62198778a6b79e2c642299 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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