2

I am attempting to trace out the shape of a path that I've place into a CAShapeLayer. In this function, the points in the points array represent the vertices of a regular polygon. The animation isn't happening, though. It's just appearing, totally animated.

Here is the code:

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

What I expect is that it will draw the stroke over the duration that I have set (30 seconds at the moment), but instead, it just appears, fully drawn with no animation.

Any thoughts?

Greg
  • 451
  • 6
  • 13

1 Answers1

5

I'm sure you already found the answer but from what I understand is that the animateWithDuration method can only animate about 8 different properties and the EndAngle is not one of them. Only CAAnimations can do this. animateWithDuration and CAAnimations are built for different things.

Quote from the ios documentation:

The following properties of the UIView class are animatable:

@property frame

@property bounds

@property center

@property transform

@property alpha

@property backgroundColor

@property contentStretch

Community
  • 1
  • 1
Orion
  • 1,258
  • 2
  • 14
  • 32
  • 1
    This is an FYI and good to know but should not be marked as the right answer as it didn't address how to animate strokeEnd but gave details about why you can't use the above method. – Ace Green Nov 23 '15 at 19:58