小编Gre*_*reg的帖子

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

我试图找出我放入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秒)上绘制笔画,但相反,它只是出现,完全没有动画.

有什么想法吗?

animation cashapelayer ios swift

2
推荐指数
1
解决办法
911
查看次数

标签 统计

animation ×1

cashapelayer ×1

ios ×1

swift ×1