Код: Выделить всё
import SwiftUI
struct GraphicDictView: View {
@State private var lines: [CGPoint] = []
@State private var circleToDraw = CGPoint()
var body: some View {
Canvas { context, _ in
context.fill(
Path(ellipseIn: CGRect(
x: circleToDraw.x - 7,
y: circleToDraw.y - 7,
width: 14,
height: 14
)),
with: .color(Color.blue)
)
var path = Path()
for line in lines {
path.addLine(to: line)
}
context.stroke(path, with: .color(Color.blue), lineWidth: 2)
}
.gesture(
DragGesture()
.onChanged { value in
circleToDraw = value.location
lines.append(value.location)
}
)
}
}
[img]https://i.sstatic .net/iVOwuS7j.gif[/img]
Поведение, которого мне нужно добиться:
[img]https://i. sstatic.net/bCiQ9nUr.gif[/img]
Подробнее здесь: https://stackoverflow.com/questions/790 ... as-swiftui