Redrawing all lines every time?


#1

I couldn’t help but notice that every time you draw a new line, the whole view gets re-drawn (all completed lines, plus the new line). Is that a normal practice? I understand that in a book like this you sometimes have to do what’s easiest in one aspect, to teach other concepts, but it seems inefficient to me.


#2

When teaching something new and complex, teaching simultaneously how to do things efficiently can be quite distracting.

Also, the reader is expected to read the UIView Class Reference and View Programming Guide for iOS.


#3

I understand that due to the nature of the book they can’t always do things the most efficient way (as I mentioned in my original post), so how would this little app be improved?

Should every line be it’s own view? Would that be the standard practice?

I’m not criticizing the book. I just want to learn about what’s a good practice, and what’s not.


#4

Although giving every line its own view will make certain tasks easier (for example, detecting which line is selected (if you want them selectable)), it will be highly inefficient to do it this way if there are many lines to draw. Also you have to consider the fact that lines, can be drawn at any angle.

So, in general it is not a good idea to put every line in its own view.


#5

Ok, so last question. So the best way to do this would be to keep all lines in one view, but find a way to just keep adding lines, instead of redrawing all lines every time a new line is added/drawn?


#6

Yes, and you need to draw only the lines that lie, wholly or partially, within the passed-in rectangle.


#7

This would be an application that would benefit from OpenGL.