简体   繁体   English

iPhone动画

[英]iPhone animation

I trying to do an animation on the iPhone and I hope someone can help me out here as I'm stumped. 我试图在iPhone上制作动画,希望当我感到困惑时,有人可以在这里帮助我。

I am using CAKeyframeAnimation with CAPath to animate views around. 我将CAKeyframeAnimation与CAPath一起使用以对周围的视图进行动画处理。

I have these settings set: 我设置了以下设置:

animation.removedOnCompletion = YES; 
animation.fillMode = kCAFillModeRemoved;

So that the animation is removed from the layer when the animation finishes I want the view to respond to touches. 这样,当动画结束时,动画将从图层中删除。我希望视图能够响应触摸。 As I have found that if I set: 正如我发现的那样,如果设置:

animation.removedOnCompletion = NO;
animation.fillMode = kCAFillModeForwards;

then the view no longer responds to touches after the animation. 则动画后视图不再响应触摸。

This has also had the negative side effect of having to manually position the view to its finished location when the animation finishes. 这还具有负面影响,即动画结束时必须手动将视图定位到其完成位置。

The theory of what I'm doing works but in practice there is a jump of the view back to its original position before I can manually set its position in the animationDidStop method. 我正在做的事情理论上可行,但实际上,在我可以在animationDidStop方法中手动设置其位置之前,视图会跳回到其原始位置。

So is it possible to have the final position of animation stay and the view respond to touches? 那么是否可以保留动画的最终位置并且视图对触摸做出响应?

Setting the fill mode to kCAFileModeForwards causes the animation to appear as if it is at the last step in the animation, but it is only the appearance. 将填充模式设置为kCAFileModeForwards会使动画看起来像是在动画的最后一步,但仅仅是外观。 You actually need to set whichever property you are animating. 实际上,您需要设置要设置动画的任何属性。 If it's the position, you need to call: 如果是职位,您需要致电:

[layer setPosition:destinationPoint];

on the layer. 在层上。 Then you don't have to set the fill mode or tell it not to remove the animation on completion. 然后,您不必设置填充模式或告诉它不要在完成时删除动画。 You will need to make sure that you set the animation for key "position" in order to override the default animation with your own. 您需要确保将动画设置为关键“位置”,以便使用自己的动画覆盖默认动画。 Call -setPosition before you add the animation to the layer. 在将动画添加到图层之前,请调用-setPosition。 Something like this: 像这样:

[layer setPosition:destinationPoint];
[layer addAnimation:kfAnimation forKey:@"position"];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM