Reputation: 163
I'm developing a iOS project that involves drawing small graphics (lines and paths) on the screen.
I initially chose to use Quartz instead of OpenGL, because I need to display some basic shapes and I need to update them every 5 seconds, so I thought Quartz was better and easier.
I found out that I can't simply draw in a view, but I have to subclass a UIView and draw in the drawRect method.
In my project, the user should be able to pinch and zoom on graphics, so I planned to add a pinchgesture to the view, but I am doubtful about how to redraw everything after the pinch. Do I have to erase everything and re-add the subviews so the drawRect will trigger or is there a better way to do this?
Thanks a lot.
Upvotes: 1
Views: 103
Reputation: 437552
When using Quartz, you technically don't have to subclass the view and replace the drawRect
, but it probably is best practice. When you want to redraw your window, just call [self setNeedsDisplay];
(if calling from the subclassed view, or [self.view setNeedsDisplay];
if doing it from the view controller). This will result in calling your drawRect
method for you and it takes care of everything for you.
See the setNeedsDisplay
documentation for more information.
Upvotes: 1