drawing - Transform a view by dragging its edge (Swift) -
i try make app user can draw or add arrow, , transform arrow (translate, rotate, ...). moment, manage draw arrow , make transformations on it, able modify arrow dragging edges.
to draw arrow, create uiview height of 20px (it thickness of arrow), , width of 400 (length of arrow).
func drawarrow(frame: cgrect) { let thicknessarrow = 20 let viewhorizontalarrow = uiview() viewhorizontalarrow.frame.origin = cgpoint(x: 100, y: 600) viewhorizontalarrow.frame.size = cgsize(width: 400, height: thicknessarrow) drawdoublearrow(viewhorizontalarrow, startpoint: cgpoint(x: 0, y: thicknessviewwitharrow/2), endpoint: cgpoint(x: viewhorizontalarrow.frame.width, y: thicknessviewwitharrow/2), linewidth: 10, color: uicolor.blackcolor()) }
after that, transform uiview pan, pinch , rotate gesture.
the function "drawdoublearrow" create arrow bezierpath , add layer of uiview.
i hope these explanations clear enough :).
could me find solution ?
thanks !
uibezierpath
on it's own cannot manipulated gestures because doesn't recognize them. uiview
can recognize gestures. combined calayer
's ability transformed , it's hittest()
method, think can achieve want.
// i'm declaring layer shape layer, depending on how error thick is, may need rectangular 1 let pangesture = uipangesturerecognizer() var mylayer = cashapelayer()
viewdidload:
// i'm assuming you've created mybezierpath, arrow path mylayer.path = mybezierpath.cgpath // adding pan gesture view's controller pangesture.addtarget(self, action: #selector(movelayer)) self.addgesturerecognizer(pangesture)
movelayer:
func movelayer(_ recognizer:uipangesturerecognizer) { let p = recognizer.location(in: self) // want loop through layers wish transform if mylayer.hittest(p) != nil { mylayer.position = p } }
Comments
Post a Comment