I am trying to make an app that draws an object for the user. I now have one of those object, which is built up of an array of type [UIBezierPath]
. I then use a loop to change all the UIBezierPath
s in the array into CGPath
s and then want to animate those paths being drawn one by one. However when I try this code now it doesn't work, and I can't really find any helpful information about this online. This is the code is use to transform the array macbookPath
which consists of UIBezierPath
into CGPath
:
for path in macbookPath {
drawingPath.append(path.cgPath)
}
And then I use this code to try and draw the path:
for cgPath in drawingPath {
shapeLayer.path = cgPath
}
This is the rest of the code for the function drawForm()
which is supposed to draw the form onto a view called aiDrawView
:
@objc func drawForm() {
var drawingPath = [CGPath]()
var macbookPath = Forms.MacbookForm()
let shapeLayer = CAShapeLayer()
shapeLayer.frame = aiDrawView.bounds
for path in macbookPath {
drawingPath.append(path.cgPath)
}
for cgPath in drawingPath {
shapeLayer.path = cgPath
}
let strokeEndAnimation = CABasicAnimation(keyPath: "strokeEnd")
strokeEndAnimation.duration = 2.0
strokeEndAnimation.fromValue = 0.0
shapeLayer.add(strokeEndAnimation, forKey: "strokeEndAnimation")
}
I am very new to CAShapeLayer
and CABasicAnimation
and UIBezierPath
so any help would be tremendously appreciated!!! :D