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



我正试图找出放置在CAShapeLayer中的路径的形状。在该函数中,点阵列中的点表示正多边形的顶点。不过,动画并没有发生。它只是出现了,完全动画化了。

这是代码:

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")
    })
}

我所期望的是,它将在我设定的持续时间内绘制笔划(目前为30秒),但它只是出现,完全绘制,没有动画。

有什么想法吗?

我相信你已经找到了答案,但据我所知,animateWithDuration方法只能动画大约8个不同的属性,EndAngle不是其中之一。只有CAAnimation才能做到这一点。animateWithDuration和CAAnimations是为不同的事物构建的。

引用ios文档:

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

@属性框架

@属性边界

@房地产中心

@属性转换

@属性alpha

@属性背景彩色

@属性内容Stretch

最新更新