使用Swift中的动画块在CAShapeLayer中动画strokeEnd

Gre*_*reg 2 animation cashapelayer ios swift

我试图找出我放入CAShapeLayer的路径的形状.在此函数中,points数组中的点表示正多边形的顶点.但动画并没有发生.它只是出现,完全动画.

这是代码:

private func drawShape (point: [(x: Double, y:Double)]) {

    let shapeLayer = CAShapeLayer()

    let shapePath = UIBezierPath()
    shapePath.moveToPoint(CGPoint(x:point[point.count-1].x, y:point[point.count-1].y))

    for i in point {
        shapePath.addLineToPoint(CGPoint(x:i.x, y:i.y))
    }

    shapeLayer.path = shapePath.CGPath

    drawingSurface.layer.addSublayer(shapeLayer)

    shapeLayer.fillColor = UIColor.clearColor().CGColor
    shapeLayer.strokeColor = UIColor.blackColor().CGColor
    shapeLayer.strokeEnd = 0

    UIView.animateWithDuration(30, delay: 0, options: .CurveEaseInOut, animations: {
        shapeLayer.strokeEnd = 1
        }, completion: {finished in println("This Finished")
    })
}
Run Code Online (Sandbox Code Playgroud)

我期望它会在我设定的持续时间(此刻为30秒)上绘制笔画,但相反,它只是出现,完全没有动画.

有什么想法吗?

Ori*_*ion 5

我相信你已经找到了答案,但据我所知,animateWithDuration方法只能动画大约8个不同的属性,而EndAngle不是其中之一.只有CAAnimations可以做到这一点.animateWithDuration和CAAnimations是针对不同的东西构建的.

从ios文档引用:

UIView类的以下属性是可动画的:

@property框架

@property界限

@property中心

@property变换

@property alpha

@property backgroundColor

@property contentStretch