0

我需要使用 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];
4

1 回答 1

5

您可以在此处找到执行此操作的示例代码。

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

备注您的代码:

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

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

代替

CABasicAnimation *opacityAnim = [CABasicAnimation animationWithKeyPath:@"alpha"];
于 2012-05-26T09:11:30.557 回答