我正在尝试在我的 iPhone 应用程序中执行某种图层动画。无论我做什么,我总是得到相同的结果:动画完成后,它会猛然回到原来的位置。即使我将 removedOnCompletion
设置为 false,也没有区别。
我在这里缺少什么?
提前致谢!
编辑:这个人真的需要帮助。我使用 CAKeyframeAnimation
和 CABasicAnimation
对象创建动画,然后将它们添加到 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"];
最佳答案
关于iphone - 为什么我的核心动画转换总是返回到它的开始状态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1865099/