【问题标题】:CAKeyFrameAnimation presentation layer seems not to changeCAKeyFrameAnimation 表示层似乎没有改变
【发布时间】:2015-04-05 06:21:57
【问题描述】:

我正在使用 CAKeyframeAnimation 在圆形轨迹上移动 CALayer。有时我需要停止动画并将动画移动到动画停止的点。代码如下:

CAKeyframeAnimation* circlePathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
CGMutablePathRef circularPath = the circle path;

circlePathAnimation.path = circularPath;
circlePathAnimation.delegate = self;
circlePathAnimation.duration = 3.0f;
circlePathAnimation.repeatCount = 1;
circlePathAnimation.fillMode = kCAFillModeForwards;
circlePathAnimation.removedOnCompletion = NO;
circlePathAnimation.timingFunction = [CAMediaTimingFunction functionWithControlPoints:.43 :.78 :.69 :.99];
[circlePathAnimation setValue:layer forKey:@"animationLayer"];
[layer addAnimation:circlePathAnimation forKey:@"Rotation"];


- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
{
    CALayer *layer = [anim valueForKey:@"animationLayer"];
    if (layer) {
        CALayer *presentationLayer = layer.presentationLayer;
        layer.position = presentationLayer.position;
    }
}

但是表示层的位置没有变化!!!我从 ios 8 读到它不再可靠。那么有没有其他方法可以找到动画层的当前位置?

【问题讨论】:

  • 我已经获得了使用 iOS 8 中的表示层为对象设置动画的位置(实际上是 frame.origin),而且它似乎工作正常。您能否提供一个参考,说明您在哪里读到它不再可靠?我用presentationLayer.position对其进行了测试,结果也很有效。

标签: ios core-animation calayer cakeyframeanimation


【解决方案1】:

我不知道表示层的位置属性不再告诉您层在 iOS 8 中的位置。这很有趣。在表示层上使用 hitTest 方法进行命中测试仍然有效,我只是在我不久前编写的一个应用上尝试过。

暂停和恢复动画也仍然有效。

对于像圆形路径这样的简单路径,您可以检查动画的时间,然后使用 trig 计算位置。

对于更复杂的路径,您必须了解您的图层所经过的路径。随着时间的推移绘制单个三次或二次贝塞尔曲线非常简单,但是其中混合了不同形状的复杂 UIBezierPath/CGPath 将很难弄清楚。

【讨论】:

    猜你喜欢
    • 2013-07-10
    • 2021-03-16
    • 1970-01-01
    • 1970-01-01
    • 2013-11-01
    • 1970-01-01
    • 2014-07-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多