Situatie
Solutie
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
Leave A Comment?