Ich möchte mehr als eine gerade Linie in Kerngrafiken zeichnen. oder speichern Sie die Zeile und starten Sie eine neue. Ich habe zwei Variablen für Berührungsposition und Berührungsstelle ihnen zugeordneten in Kontakt Begann, Verschoben, Ended dann habe ich dies:Zeichnen von Linien mit Kerngrafiken
override func draw(_ rect: CGRect) {
let context = UIGraphicsGetCurrentContext()
context?.setStrokeColor(UIColor(red: 0, green: 0, blue: 0, alpha: 1.0).cgColor)
context?.setLineWidth(5.0)
context?.move(to: CGPoint(x: firstTouchLocation.x, y: firstTouchLocation.y))
context?.addLine(to: CGPoint(x: lastTouchLocation.x, y: lastTouchLocation.y))
context?.strokePath()
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
if let touch = touches.first {
firstTouchLocation = touch.location(in: self)
lastTouchLocation = firstTouchLocation
setNeedsDisplay()
}
}
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
if let touch = touches.first {
lastTouchLocation = touch.location(in: self)
setNeedsDisplay()
}
}
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
if let touch = touches.first {
lastTouchLocation = touch.location(in: self)
setNeedsDisplay()
}
}
Also, was ist das Problem? –
die Zeile verschwindet und beginnt eine neue Ich möchte die Zeile speichern und starten Sie eine neue –
@MohmedShowekh würden Sie den beschreibenden Problemkommentar zur Frage hinzufügen –