Skip to content

Instantly share code, notes, and snippets.

@JonFir
Created January 20, 2018 06:22
Show Gist options
  • Save JonFir/20208e98f4fe895366e5180f71fd2bae to your computer and use it in GitHub Desktop.
Save JonFir/20208e98f4fe895366e5180f71fd2bae to your computer and use it in GitHub Desktop.
- (CAAnimationGroup*)makeSuccessIconAnimation
{
CGFloat const animationDuration = 0.4;
CAAnimationGroup *animation = [CAAnimationGroup animation];
animation.delegate = self;
[animation setValue:_successIconAnimationId forKey:_animationIdKeyName];
CABasicAnimation *appearAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
appearAnimation.fromValue = @0.0;
appearAnimation.toValue = @1.0;
appearAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
appearAnimation.duration = animationDuration;
appearAnimation.beginTime = 0.0;
if (self.animationType != YTSValidationViewAnimationTypeSuccessWithGlasses) {
animation.animations = @[appearAnimation];
animation.duration = animationDuration;
return animation;
}
CABasicAnimation *disappearMoveAnimation = [CABasicAnimation animationWithKeyPath:@"strokeStart"];
disappearMoveAnimation.fromValue = @0.0;
disappearMoveAnimation.toValue = @1.0;
disappearMoveAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
disappearMoveAnimation.duration = animationDuration;
disappearMoveAnimation.beginTime = 0.8;
CABasicAnimation *disappearFadeAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
disappearFadeAnimation.fromValue = @1.0;
disappearFadeAnimation.toValue = @0.0;
disappearFadeAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
disappearFadeAnimation.duration = animationDuration;
disappearFadeAnimation.beginTime = 0.8;
animation.animations = @[appearAnimation, disappearMoveAnimation, disappearFadeAnimation];
animation.duration = 1.2;
return animation;
}
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
{
NSString *id = [anim valueForKey:_animationIdKeyName];
if (id == NULL) {
return;
}
const CGFloat glassesShowDalay = 0.2f;
if ([id isEqualToString:_successIconAnimationId] && self.animationType == YTSValidationViewAnimationTypeSuccessWithGlasses) {
[self hideSuccessIcon];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(glassesShowDalay * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self showGlasses];
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment