UIViews动画 - Objective-C

时间:2011-07-04 18:57:57

标签: objective-c uiview uiviewcontroller uibutton

目前,我想出了如何为我的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"];

但这是基于logoLayer,这是一个图像。我怎么能为这样的东西制作动画,但对于UIView?比如UIButton?

1 个答案:

答案 0 :(得分:0)

通常,您可以使用UIView animation,而不是在CAAnimation上使用CALayer。有一些方法可以使用基于块的动画API或旧的基于委托的API来设置动画曲线,延迟,重复,反转等。

至于CAKeyframeAnimation的具体情况,您可以尝试this question的答案。