动画从线到曲线的转换

时间:2014-08-20 08:08:39

标签: ios objective-c iphone core-animation bezier

绘制动画反弹曲线时遇到问题。 下面的代码允许动画线的所需效果,但是当弯曲时我不想看到直线。我的代码错了吗?任何评论或指导都非常感谢。

干杯

enter image description here

enter image description here

- (void)loadView
{
    //up Path
    upPath  = CGPathCreateMutable();
    CGPathMoveToPoint(upPath, nil,startingDrawPointX,startingDrawPointY);
    CGPathAddQuadCurveToPoint(upPath, nil, controlPoint.x, 100, endingDrawPointX, endingDrawPointY);
    CGPathCloseSubpath(upPath);

    //down Path
    downPath = CGPathCreateMutable();
    CGPathMoveToPoint(downPath, nil,startingDrawPointX,startingDrawPointY);
    CGPathAddQuadCurveToPoint(downPath, nil, controlPoint.x, 70, endingDrawPointX, endingDrawPointY);
    CGPathCloseSubpath(downPath);

    //mid Path
    midPath = CGPathCreateMutable();
    CGPathMoveToPoint(midPath, nil,startingDrawPointX,startingDrawPointY);
    CGPathAddQuadCurveToPoint(midPath, nil, controlPoint.x, controlPoint.y, endingDrawPointX, endingDrawPointY);
    CGPathCloseSubpath(midPath);


    //Create Shape

    shapeLayer = [CAShapeLayer layer];
//  shapeLayer.path = midPath;
    shapeLayer.fillColor = nil;
    shapeLayer.strokeColor = kDBrownTextColor.CGColor;
    shapeLayer.lineWidth = 2.0;
//  shapeLayer.fillRule = kCAFillRuleNonZero;
    [self.layer addSublayer:shapeLayer];
    [self performSelector:@selector(startAnimation) withObject:nil afterDelay:1.5];

}

-(void)startAnimation
{
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"path"];
    animation.duration = 1;
    animation.repeatCount = maxCount;
    animation.autoreverses = YES;
    animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    animation.fromValue = (__bridge id)downPath;
    animation.fromValue =(__bridge id)midPath;
    animation.toValue = (__bridge id)upPath;
    [shapeLayer addAnimation:animation forKey:@"animatePath"];
}

1 个答案:

答案 0 :(得分:2)

CGPathCloseSubpath注释掉这些行 - 他们正在创建你看到的直线