简体   繁体   English

使用Core Animation的生涩动画

[英]jerky animation using Core Animation

In my iPhone app, I am trying to get some red and white stripes that are scrolling across the screen to animate smoothly when the speed of the stripes gets high. 在我的iPhone应用程序中,我试图获得一些红色和白色的条纹,当条纹的速度变高时,它们会在屏幕上滚动以平滑地进行动画处理。 In my app the user starts the animation and changes the scrolling speed by a finger swipe and changes the width of the stripes by a two finger pinch. 在我的应用程序中,用户开始动画并通过手指滑动来更改滚动速度,并通过两根手指的捏合来更改条纹的宽度。 Animation is stopped in response to a double tap. 响应双击,动画停止。 If the speed gets high or the stripes get narrow the animation is no longer smooth to the eye. 如果速度变高或条纹变窄,动画将不再平滑。 The edges of the stripes seem to jump around. 条纹的边缘似乎在跳来跳去。

The animation is simple. 动画很简单。 I draw the stripes in a layer that's a bit larger than the screen. 我在比屏幕大一点的层中绘制条纹。 I then set up an animation that moves the layer position by exactly the distance from one red stripe to the next. 然后,我设置了一个动画,该动画将图层位置从一个红色条纹到下一个红色条纹的精确距离移动。 The duration is set by the speed of the finger swipe and the repeat count is 1. When the animation stops the delegate checks a flag to see if the user wants to stop the scrolling. 持续时间由手指滑动的速度设置,重复计数为1。当动画停止播放时,委托检查标志以查看用户是否要停止滚动。 If not, the animation is restarted again for one cycle. 如果不是,动画将重新启动一个周期。 Are there better ways of doing this so that the animation is smooth at high speeds or with narrow stripes? 是否有更好的方法来使动画在高速或窄条纹下平滑?

Thanks-- 谢谢 -

Off hand guess: since each animation covers the distance of one pair of stripes, as you decrease the width of the stripes, the number of animations per second will go up, so the proportion of time spent setting up a new animation and resetting the layer goes up as width goes down. 临时猜测:由于每个动画都覆盖一对条纹的距离,因此当您减小条纹的宽度时,每秒的动画数量将增加,因此设置新动画和重置图层所花费的时间比例随着宽度减小而增加。

The fix then would be to increase the distance covered by each animation as the stripes get narrow. 解决方法是,随着条纹变窄,增加每个动画覆盖的距离。 So, instead of animating from one red stripe to the next, you animate to the nth one. 因此,您无需对一个红色条纹进行动画处理,而是对第n个动画进行动画处理。 If you increase n as the strips get smaller, you'll be able to hold the animations per second roughly steady. 如果随着条带变小而增加n,则可以每秒大致稳定地保持动画。

In terms of animations per second, increasing the speed is the same as narrowing the strips. 就每秒动画而言,增加速度与缩小条带相同。 So the fix is the same: As the speed goes up, increase n. 因此解决方法是相同的:随着速度的提高,增加n。

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

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