为什么我的核心动画转换总是返回到起始状态?

5

我正在尝试在我的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个回答

3

不确定这是否有帮助,但是这个人似乎遇到了类似的问题。

你可能需要在动画运行时设置图层的transform属性为transformLeafToRotation

祝好运!


非常感谢Frank Schmitt!你太棒了。 theAnimationGroup.fillMode = kCAFillModeForwards; 是关键。 如果你来斯德哥尔摩,我欠你一杯咖啡。=) - ABeanSits

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接