Skip to content

Instantly share code, notes, and snippets.

@rbrovko
Created February 16, 2016 13:02
Show Gist options
  • Save rbrovko/46ebeff3b2d827b68243 to your computer and use it in GitHub Desktop.
Save rbrovko/46ebeff3b2d827b68243 to your computer and use it in GitHub Desktop.
- (void)squareToCircleToRoundedRectangle {
// self.circleView.layer.masksToBounds = YES;
// self.circleView.layer.position = self.circleView.frame.origin;
// self.circleView.layer.anchorPoint = CGPointMake(0.0f, 0.0f);
// self.circleView.layer.cornerRadius = MIN(self.circleView.frame.size.width, self.circleView.frame.size.height) / 2.0f;
CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"cornerRadius"];
anim.removedOnCompletion = NO;
anim.fromValue = @(self.circleView.layer.cornerRadius);
anim.toValue = @(kKruMainMaxWidthCircleView / 2);
anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
anim.duration = kKruMainAnimationDuration;
anim.beginTime = 0.0f;
anim.autoreverses = NO;
CGRect oldBounds = self.circleView.layer.bounds;
CGRect newBounds = oldBounds;
newBounds.size = CGSizeMake(kKruMainMaxWidthCircleView, kKruMainMaxWidthCircleView);
CABasicAnimation *anim2 = [CABasicAnimation animationWithKeyPath:@"bounds"];
anim2.removedOnCompletion = NO;
anim2.fromValue = [NSValue valueWithCGRect:oldBounds];
anim2.toValue = [NSValue valueWithCGRect:newBounds];
anim2.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
anim2.duration = kKruMainAnimationDuration;
anim2.beginTime = 0.0f;
// CABasicAnimation *anim3 = [CABasicAnimation animationWithKeyPath:@"bounds.size.height"];
// anim3.removedOnCompletion = NO;
// anim3.fromValue = @(20);
// anim3.toValue = @(kKruMainMaxWidthCircleView);
// anim3.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
// anim3.duration = kKruMainAnimationDuration;
// anim3.beginTime = 0.0f;
//
CAAnimationGroup *group = [CAAnimationGroup animation];
group.animations = @[anim, anim2];
group.duration = kKruMainAnimationDuration;
group.beginTime = 0.0f;
group.removedOnCompletion = NO;
group.repeatCount = INFINITY;
// [self.circleView.layer addAnimation:anim forKey:@"cornerRadius"];
[self.circleView.layer addAnimation:anim forKey:@"animation"];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment