CAKeyFrameAnimation中keyTime的值是什么? [英] What kind of value is keyTime in an CAKeyFrameAnimation?

查看:545
本文介绍了CAKeyFrameAnimation中keyTime的值是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,我有这个CAKeyFrameAnimation:

For example I have this CAKeyFrameAnimation:

CALayer* theLayer = myView.layer;
    CAKeyframeAnimation* animation;
    animation = [CAKeyframeAnimation animationWithKeyPath:@"transform.rotation.z"];

    animation.duration = 1.6;
    //animation.cumulative = YES;
    animation.repeatCount = 1;
    animation.removedOnCompletion = NO;
    animation.fillMode = kCAFillModeForwards;

    animation.values = [NSArray arrayWithObjects:
                        [NSNumber numberWithFloat:0.0 * M_PI],
                        [NSNumber numberWithFloat:(15.0/180.0) * M_PI],
                        [NSNumber numberWithFloat:(30.0/180.0) * M_PI], // animation stops here...
                        [NSNumber numberWithFloat:(45.0/180.0) * M_PI], // ignored!
                        [NSNumber numberWithFloat:(190.0/180.0) * M_PI], nil]; // ignored!

    animation.keyTimes = [NSArray arrayWithObjects:
                          [NSNumber numberWithFloat:0.0],
                          [NSNumber numberWithFloat:0.2],
                          [NSNumber numberWithFloat:0.4], // ignored!
                          [NSNumber numberWithFloat:0.8], // ignored!
                          [NSNumber numberWithFloat:1.6], nil]; // ignored!

    animation.timingFunctions = [NSArray arrayWithObjects:
                                 [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear], 
                                 [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear],
                                 [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear],
                                 [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear],
                                 [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear], nil];

    [theLayer addAnimation:animation forKey:@"transform.rotation.z"];

我得不到的是:

A)是自动画开始以来的绝对传递时间的关键时间值吗?

A) are key time values absolute passed time since the animation has started?

B)是关键时间值,只是说这个特定关键帧需要多少时间?

B) are key time values just saying how much time to use for this particular key frame?

推荐答案

docs 在这里有点奇怪,但准确无误:

The docs are phrased a little oddly here, but are accurate:


数组中的每个值都是0.0到1.0之间的浮点数,对应于values数组中的一个元素。 keyTimes数组中的每个元素将相应关键帧值的持续时间定义为动画总持续时间的一部分。每个元素值必须大于或等于前一个值。

Each value in the array is a floating point number between 0.0 and 1.0 and corresponds to one element in the values array. Each element in the keyTimes array defines the duration of the corresponding keyframe value as a fraction of the total duration of the animation. Each element value must be greater than, or equal to, the previous value.

基本上,每个值都表示在什么标准化点动画给定的关键帧发生。因此,如果关键帧是动画的25%,则值为0.25。文档中令人困惑的部分是它们表明它是一个持续时间,实际上它是一个标准化的时间点。

Basically, each value indicates at what normalized point in the animation the given keyframe occurs. So if a keyframe is 25% into the animation, the value would be 0.25. The confusing part of the docs is they indicate that it is a duration, when in fact it's a normalized point in time.

这篇关于CAKeyFrameAnimation中keyTime的值是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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