Is there a way to animate the stroke drawing of a path whenever its destination point changes?
Here is a snippet of my code:
struct JourneyMapLineView: View {
@Binding var rects: [CGRect]
var body: some View {
rects.count != 0 ?
JourneyMapLineShape(startRect: rects[0], endRect: rects[rects.count-1])
.stroke(Color.red), lineWidth: 8)
.animation(.easeInOut(duration: 0.3)) //<-- Is not working
: nil
}
}
struct JourneyMapLineShape: Shape {
var startRect: CGRect
var endRect: CGRect
func path(in _: CGRect) -> Path {
var path = Path()
path.move(to: startRect.origin)
path.addLine(to: endRect.origin)
return path
}
}
Currently, as you can see, there is no animation by changing the value of endRect
:
I have already looked at some similar questions, it seems that this is a new case,.
Thank you so much!