Currently, I figured out how to animate an image that is in my UIViewController:
UIImage *image = [UIImage imageNamed:@"Logo.png"];
CALayer *logoLayer = [CALayer layer];
logoLayer.bounds = CGRectMake(0, 0, image.size.width, image.size.height);
logoLayer.position = CGPointMake(300, 216);
logoLayer.contents = (id)image.CGImage;
CAKeyframeAnimation *moveAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
moveAnimation.path = path.CGPath;
moveAnimation.duration = 2.0f;
[logoLayer addAnimation:moveAnimation forKey:@"moveAnimation"];
CAAnimationGroup *animationGroup = [CAAnimationGroup animation];
animationGroup.duration = 2.0f;
animationGroup.autoreverses = NO;
animationGroup.repeatCount = 1; //HUGE_VALF
[animationGroup setAnimations:[NSArray arrayWithObjects: moveAnimation, nil]];
[logoLayer addAnimation:animationGroup forKey:@"animationGroup"];
But this is based on a logoLayer, which is an image. How could I animate something like this but for a UIView? Such as a UIButton?
In general, rather than using
CAAnimations onCALayers, you can useUIViewanimation. There are ways to set animation curve, delay, repeat, reversal, and so on using the block-based animation API or the old delegate-based API.As for your specific case of the
CAKeyframeAnimation, you can try the answer to this question.