I need to create a simple drawing app. This app consists of a line with two anchor points, one at each end. The user should have the ability to touch down on an anchor point and drag it to manipulate the line’s length and slope. Also the user should be able to touch down on the line connecting the two anchor points to move it and the anchor points around the screen.
I’m kind of stumped here, I know that I could probably do the manipulation of the length and slope by simply using touch down/up but I do not think this will work for multiple lines?! Can anyone point me in the direction I should be looking please? Many thanks 🙂
Edit: I rewrote the answer, this time by implementing a short test. The source code below does the following: On a touch down, it checks the distance of every point inside the list
self.lineDrawView.linesto the current touch point. If the distance is below 10 px, the current touch point and its list index is saved.If no matching point is found, another function iterates through all lines made up from pairs inside
self.lineDrawView.linesand calculates the distance to each line (distance to line code borrowed here). Again, if the distance is below 10 px, the current touch point as well as the starting and ending point of the current line are saved.Then, on a touch move, either the saved point is moved or the saved line is recalculated by the distance between the previous touch down point and the current touch position.
Header of your view controller:
Source of your view controller:
Header of view for drawing:
Source of view for drawing: