Quote:
Originally Posted by kpearce2
Hi,
I'm struggling with this. I have created an app that allows the user to draw to the screen with their finger. simple. What I want to be able to do is allow the user to select that line and move it if they wished to. How would I go about giving this line a reference so that it can be called? I currently have the lines being drawn to a uiimage - maybe that isn't the best way to go about it.
Thanks for any help.
|
The easiest thing to do would be to make each line be it's own UIImage object. Then you could add a gesture recognizer to it and the user could drag it around.
If you've got 100 or less, do that. If you're creating more than that, you need another approach, because views are fairly large and complex, and you run the risk of running out of memory, or at least bogging down drawing as all those overlapping lines have to be drawn.
Alternately, you could create a custom subclass of UIView that manages an array of line objects, and asks each of them to draw itself. You could make the line objects be NSObjects, not views. They would use the drawing context of the view they belong to, and would be called on to draw themselves from the enclosing view's drawRect method. To do that, you'd have to write some rather complex code in your custom view that hit tests the different line objects to figure out which one the user is dragging, and asks it to update itself while the user is dragging it around.