为什么我的核心动画转换总会回到它的启动状态?

时间:2009-12-08 06:53:13

标签: iphone cocoa cocoa-touch core-animation

我正在尝试在我的iPhone应用程序中执行某种层的动画。无论我做什么,我总能得到相同的结果:动画完成后,它会回到原来的位置。即使我将removedOnCompletion设置为false,也没有区别。

我在这里缺少什么?

提前致谢!

编辑:真的需要帮助这个人。我正在使用CAKeyframeAnimationCABasicAnimation个对象创建动画,然后将它们添加到CAAnimationGroup,我依次将其添加到图层。动画按预期工作,但它总是快速恢复到原始状态。即使我在所有动画对象和动画组上设置removedOnCompletion = NO;,情况也是如此。

有人请指出我正确的方向!我住在斯德哥尔摩地区,我会给你买一杯咖啡。 =)下面发布的新代码:

CABasicAnimation *leveloutLeafAnimation = [CABasicAnimation animationWithKeyPath:@"transform"];
leveloutLeafAnimation.removedOnCompletion = NO;
leveloutLeafAnimation.duration = 1.0; 
leveloutLeafAnimation.repeatDuration = 20; 
CATransform3D transformLeafToRotation = CATransform3DMakeRotation(0.0, 0.0, 0.0, 1);
CATransform3D transformLeafFromRotation = CATransform3DMakeRotation([self _degreesToRadians:270.0], 0.0, 0.0, 1);
leveloutLeafAnimation.fromValue = [NSValue valueWithCATransform3D:transformLeafFromRotation];
leveloutLeafAnimation.toValue = [NSValue valueWithCATransform3D:transformLeafToRotation];

//Create an animation group to combine the animations.
CAAnimationGroup *theAnimationGroup = [CAAnimationGroup animation];

//The animationgroup conf.
theAnimationGroup.delegate = self;
theAnimationGroup.duration = animationDuration;
theAnimationGroup.removedOnCompletion = NO;
theAnimationGroup.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
theAnimationGroup.animations = [NSArray arrayWithObjects:leveloutLeafAnimation, leafMoveAnimation, nil];

// Add the animation group to the leaf layer.
[leafViewLayer addAnimation:theAnimationGroup forKey:@"animatLeafFalling"];

1 个答案:

答案 0 :(得分:3)

不确定这是否有用,但this guy似乎他遇到了类似的问题。

当动画运行到transform时,您可能必须设置图层的transformLeafToRotation属性。

祝你好运!