iphone sdk中的CA基本动画

时间:2012-05-26 09:03:20

标签: iphone cabasicanimation

我需要使用CA BASIC ANIMATION同时旋转和移动相同的图像,在iphone sdk中是否有任何出路

任何帮助都将受到高度赞赏


这是我的代码

 imgview = (UIImageView *)[self.view viewWithTag:imagenumber];
 CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"position"];
 anim.fromValue  = [NSValue valueWithCGPoint:CGPointMake(160 + x_movefrom, 240 + y_movefrom)];
 anim.toValue    = [NSValue valueWithCGPoint:CGPointMake(160 + x_moveto, 240 + y_moveto)];
 anim.duration   = 2;
 anim.removedOnCompletion = YES;

 //imgview = (UIImageView *)[self.view viewWithTag:imagenumber];

CABasicAnimation *opacityAnim = [CABasicAnimation animationWithKeyPath:@"alpha"];
opacityAnim.fromValue = [NSNumber numberWithFloat:1.0];
opacityAnim.toValue = [NSNumber numberWithFloat:0.0];
opacityAnim.removedOnCompletion = NO;

CAAnimationGroup *animGroup = [CAAnimationGroup animation];
animGroup.animations = [NSArray arrayWithObjects:opacityAnim,anim, nil];
animGroup.duration = 2;
animGroup.delegate = self;
animGroup.removedOnCompletion = NO;
[imgview.layer addAnimation:animGroup forKey:nil];

1 个答案:

答案 0 :(得分:5)

您可以找到here示例代码来执行此操作。

关键是创建两个CABasicAnimation,然后将它们分组到CAAnimationGroup

重新阅读您的代码:

为不透明度设置动画,请尝试使用:

CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"opacity"];

而不是

CABasicAnimation *opacityAnim = [CABasicAnimation animationWithKeyPath:@"alpha"];