ios - How to move a line created with UIBezierPath? -
i want move line. use touchesmoved it. line shifted relative location of finger 100 pixels. why happen?
func drawline() { let line = cashapelayer() let linepath = uibezierpath() linepath.move(to: to: cgpoint(x: 100, y: 100) linepath.addline(to: cgpoint(x: self.view.frame.width - 100, y: 100)) line.path = linepath.cgpath line.strokecolor = uicolor.red.cgcolor line.linewidth = 1 line.linejoin = kcalinejoinround self.view.layer.addsublayer(line) } override func viewdidload() { super.viewdidload() drawline() } override func touchesmoved(_ touches: set<uitouch>, event: uievent?) { let touch = touches.first guard let location = touch?.location(in: self.view) else { return } line.frame.origin = cgpoint(x: location.x-line.frame.size.width/2, y: location.y-line.frame.size.height/2) }
this because not starting line drawing cgpoint.zero. change
linepath.move(to: to: cgpoint(x: 100, y: 100) linepath.addline(to: cgpoint(x: self.view.frame.width - 100, y: 100)) to
linepath.move(to: .zero) linepath.addline(to: cgpoint(x: 100, y: 0))
Comments
Post a Comment