Animating Bezier curve as though drawing proceeds on iPhone screen

前端 未结 3 1044
眼角桃花
眼角桃花 2020-12-28 23:19

I want to draw a bezier path of the outline of Taj Mahal\'s tomb.

Q1. How could I draw it in XCode? I could easily do that in PS but am finding it difficult to do in

3条回答
  •  感动是毒
    2020-12-28 23:48

    I blogged about this in 2010: Animating the Drawing of a CGPath With CAShapeLayer.

    The gist of it is this:

    • Create a UIBezierPath or CGPath with the shape you want to draw. Use the methods moveToPoint:, addLineToPoint:, addCurveToPoint:controlPoint1:controlPoint2: etc. to create the shape.
    • Create a CGShapeLayer and assign the path to the layer's path property.
    • Add the layer to your view/layer hierarchy (e.g. in a view controller: [self.view.layer addSublayer:shapeLayer];). You also have to give the layer a valid size and position (frame).
    • Animate the layer's strokeEnd property from 0 to 1.

提交回复
热议问题