我正在尝试在我的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"];