有人知道如何在自定义视图中设置UIBezierPath的绘制动画吗?因此,看起来iPhone已经拿起一支笔,并且在屏幕上画得足够慢以便看到它。
说我的路径如下:
var bezierPath = UIBezierPath()
bezierPath.moveToPoint(CGPointMake(49.5, 14.5))
bezierPath.addCurveToPoint(CGPointMake(106.5, 14.5), controlPoint1: CGPointMake(106.5, 14.5), controlPoint2: CGPointMake(106.5, 14.5))
bezierPath.addCurveToPoint(CGPointMake(119.5, 26.5), controlPoint1: CGPointMake(106.5, 14.5), controlPoint2: CGPointMake(119.5, 14.5))
bezierPath.addCurveToPoint(CGPointMake(119.5, 75.5), controlPoint1: CGPointMake(119.5, 38.5), controlPoint2: CGPointMake(119.5, 75.5))
bezierPath.addCurveToPoint(CGPointMake(106.5, 88.5), controlPoint1: CGPointMake(119.5, 75.5), controlPoint2: CGPointMake(122.5, 88.5))
bezierPath.addCurveToPoint(CGPointMake(49.5, 88.5), controlPoint1: CGPointMake(90.5, 88.5), controlPoint2: CGPointMake(49.5, 88.5))
bezierPath.addCurveToPoint(CGPointMake(36.5, 75.5), controlPoint1: CGPointMake(49.5, 88.5), controlPoint2: CGPointMake(36.5, 89.5))
bezierPath.addCurveToPoint(CGPointMake(36.5, 26.5), controlPoint1: CGPointMake(36.5, 61.5), controlPoint2: CGPointMake(36.5, 26.5))
bezierPath.addCurveToPoint(CGPointMake(49.5, 14.5), controlPoint1: CGPointMake(36.5, 26.5), controlPoint2: CGPointMake(35.5, 14.5))
UIColor.redColor().setFill()
bezierPath.fill()
UIColor.blackColor().setStroke()
bezierPath.lineWidth = 10
bezierPath.stroke()
这会绘制一个圆角矩形,并写在自定义类的drawRect函数中。
有人知道如何为此画图制作动画吗?
答案 0 :(得分:7)
您可以考虑使用CAShapeLayer并为strokeEnd
属性设置动画(您可以使用CABasicAnimation来控制动画的详细信息)。 This post有一个例子。