【问题标题】:CAKeyframeAnimation repeat animation from begin to endCAKeyframeAnimation 从头到尾重复动画
【发布时间】:2013-07-17 01:50:46
【问题描述】:

我需要为 UIImageView 添加从起点到终点以及从终点到起点的无限动画。 我正在尝试这样:

CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
pathAnimation.calculationMode = kCAAnimationPaced;
pathAnimation.fillMode = kCAFillModeForwards;
pathAnimation.removedOnCompletion = NO;
pathAnimation.duration = 2.0;
pathAnimation.repeatCount = HUGE_VALF;
pathAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];

CGPoint endPoint = CGPointMake(320.0f - 30.0f, self.myImage.frame.size.height);
CGMutablePathRef curvedPath = CGPathCreateMutable();
CGPathMoveToPoint(curvedPath, NULL, self.myImage.frame.origin.x, self.myImage.frame.origin.y);
CGPathAddCurveToPoint(curvedPath, NULL, endPoint.x, self.myImage.frame.origin.y,
                      endPoint.x, self.myImage.frame.origin.y, endPoint.x, endPoint.y);
pathAnimation.path = curvedPath;
CGPathRelease(curvedPath);

[self.myImage.layer addAnimation:pathAnimation forKey:@"curveAnimation"];

myImage 从起点移动到终点没问题,但之后移动到起点并从起点到终点重复动画。所以,从终点到起点没有动画。有可能吗?

【问题讨论】:

    标签: ios animation cakeyframeanimation


    【解决方案1】:

    以与您相同的方式返回动画就像将 autoreverses 设置为 YES 一样简单。

    也就是说,如果它真的是无限动画,那么你不需要fillModeremovedOnCompletion

    【讨论】:

      【解决方案2】:

      我是你,我会简单地使用:

      [UIVIew animateWithDuration:delay:options:animations:completion:]

      有选项

      UIViewAnimationOptionRepeat

      【讨论】:

        猜你喜欢
        • 2014-10-31
        • 2013-04-02
        • 1970-01-01
        • 2017-09-25
        • 2015-04-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多