我的核心动画变换总是返回到它的开始状态? [英] How come my Core Animation transformation always returns to it's start-state?

查看:108
本文介绍了我的核心动画变换总是返回到它的开始状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的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];

//创建一个动画组合并动画。
CAAnimationGroup * theAnimationGroup = [CAAnimationGroup animation];

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

//将动画组添加到叶层。
[leafViewLayer addAnimation:theAnimationGroup forKey:@animatLeafFalling];


解决方案

不确定这是否有帮助, =http://stackoverflow.com/questions/226555/after-animation-view-position-resets>这家伙似乎似乎有一个类似的问题。



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



祝你好运!


I am trying to perform some kind of animation of a layer in my iPhone application. It does not matter what I do I always get the same results: after the animation is done it jerks back into it's original position. Even though I set removedOnCompletion to false there is no difference.

What am I missing here?

Thanks in advance!

EDIT: Really need help with this one guys. I am creating animations with CAKeyframeAnimation and CABasicAnimation objects, then adding them to a CAAnimationGroup which I in turn att to the layer. The animation works as predicted except that it always snaps back to it's original state. This is the case even though I set removedOnCompletion = NO; on all animation-objects and the animation group.

Some one please point me in the right direction! I you live in the Stockholm area I will buy you a coffe. =) New code posted below:

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"];

解决方案

Not sure if this is helpful, but this guy seems like he was having a similar problem.

You might have to set the transform property of the layer while the animation is running to transformLeafToRotation.

Good luck!

这篇关于我的核心动画变换总是返回到它的开始状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆