我是一个从android转ios的开发人员。请问下ios下如何实现逐帧动画

我是一个刚从android转ios的开发人员,在android中制作帧动画,一个xml帧布局文件,然后在程序中用AnimationDrawable对象直接start()就行了,但是在ios中我一直没看明白要怎么弄啊,求赐教!

简单的动画用UIImageview就行了,

;//设置动画图片数组 数组中存放的是一组UIImage图片(帐动画图片)

;//设置动画持续时间

imageView.animationRepeatCount = 1;//设置动画重复次数

;//开始动画

用UIImageview如何这只每一帧的时间的,而且这些动画配置信息能不能通过外部文件来设置,直接通过代码来写动画配置信息不好分工和管理啊。

用UIImageview如何设置每一帧的时间的,而且这些动画配置信息能不能通过外部文件来设置,直接通过代码来写动画配置信息不好分工和管理啊。

那就使用:CAKeyframeAnimation;

CAKeyframeAnimation *anim=;

anim.duration=3;

anim.values=;

;

设定每一帧的时间

默认情况下,一 帧动画的播放,分割 的时间是动画的总时间除以帧数减去一。你可以通过下面的公式决定每帧动画的时间:总时间/(总帧数-1)。 例如,如果你指定了一个 5 帧,10 秒的动画,那么每帧的时间就是 2.5 秒钟:10/(5-1)=2.5。你可以做更多 的控制通过使用 keyTimes 关键字,你可以给每帧动画指定总时间之内的某个时间点。

通过设置属性keyTimes,能实现这个功能,这个属性是一个数组,其成员必须是NSNumber。

同时 这个属性的设定值要与calculationMode属性相结合,同时他们有一定的规则,

The appropriate values in the keyTimes array are dependent on the calculationMode property.

  • If the calculationMode is set to kCAAnimationLinear, the first value in the array must be 0.0 and the last value must be 1.0. Values are interpolated between the specified key times.

  • If the calculationMode is set to kCAAnimationDiscrete, the first value in the array must be 0.0.

  • If the calculationMode is set to kCAAnimationPaced or kCAAnimationCubicPaced, the keyTimes array is ignored。

如果keyTimes的值不合法,或者不符合上面的规则,那么就会被忽略。

[animation setCalculationMode:kCAAnimationLinear]; [animation setKeyTimes:
[NSArray arrayWithObjects:
[NSNumber numberWithFloat:0.0],
[NSNumber numberWithFloat:0.25], ,
[NSNumber numberWithFloat:0.75], , nil]];