有人知道如何在自定义视图中设置UIBezierPath的绘制动画吗?所以看起来iPhone已经拿起一支笔,并且在屏幕上画得足够慢以便看到它. 只是说我有一条如下路径: var bezierPath = UIBezierPath()b
只是说我有一条如下路径:
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函数内.
有谁知道如何动画这个画的?
您可以考虑使用 CAShapeLayer并设置strokeEnd属性的动画(您可以使用CABasicAnimation来控制动画的细节). This post有一个例子.