Having code that draws custom shape with the following code:
struct ProgressPath: Shape {
var numberOfPoints: Int = 2
var animatableData: CGFloat {
get { CGFloat(numberOfPoints) }
set { numberOfPoints = Int(newValue) }
}
var sectionsByItems: [IndexPath] {
var result: [IndexPath] = []
for index in 0..<numberOfPoints {
guard let lastItem = result.last?.row else {
result.append(IndexPath(item: 0,
section: 0))
continue
}
let currentSection = Int(index / 2)
if index % 2 == 0 {
result.append(IndexPath(item: lastItem,
section: currentSection))
} else {
result.append(IndexPath(item: lastItem == 1 ? 0 : 1,
section: currentSection))
}
}
return result
}
func point(indexPath: IndexPath,
rect: CGRect)-> CGPoint {
let distance = rect.width - 40
return CGPoint(x: indexPath.row == 0 ? distance : 40,
y: (rect.height - 20) - 50 * (CGFloat(indexPath.section)))
}
func path(in rect: CGRect) -> Path {
var path = Path()
sectionsByItems
.forEach { indexPath in
let newPoint = point(indexPath: indexPath,
rect: rect)
if indexPath.section == 0 &&
indexPath.row == 0 {
path.move(to: newPoint)
} else {
path.addLine(to: newPoint)
}
}
return path
}
}
Which looks like the following:
I want to add shapes on top of the created path, ideally, I want to have some mechanism that should look something like this where circles on top of the path are interactable:
Little lost how this can be achieved without modifying the original path, maybe there's a more elegant solution that can draw shapes over a custom path?
Similar questions - How to create game map for iOS?
Notes: While this is a specific question to the custom path provided above - I'm trying to come up with a method to draw custom shapes on top of any shape by following their path and make them interactable.