0

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?

StanLe
  • 5,037
  • 9
  • 38
  • 41

1 Answers1

0

In general, rather than using CAAnimations on CALayers, you can use UIView animation. 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.

Community
  • 1
  • 1
Joe Osborn
  • 1,145
  • 7
  • 10