I am writing an application that uses your finger to draw simple diagrams. It works for me for the most part, but now I'm trying to optimize its performance. When the user swipes quickly, I cannot capture enough touch events to draw a smooth path.
Here is my current approach:
1) I have subclassed UIView and added a rocker to CGLayer (created lazily and has the same size as my UIView). 2) My subclass of UIView responds to touch events, storing the current and last touch points in instance variables. 3) My view of setNeedsDisplay is also called in draw rect, do the following: - draw a line from the previous touch location to the current location of the touch to CGLayer - draw the entire CGLayer in the context of my views at a time
The main problem is that the user quickly goes over me, I get a relatively small number of touch events, so the lines that I draw between touches are long and make the path look uneven.
My questions:
1) Is drawRect (in my UIView subclass) called and touch event handlers of my UIView subclass in the same thread called? That is, can I execute streams (one in a touch-screen event, and the second in my straight line)?
If there are no touch touch events, is it called in the queue while drawRect is being called? And how can I improve performance - just improve drawRect performance?
If so, how can I get more touch events so that I can make a smoother path?
Thanks.
iphone uikit quartz-graphics drawing
aloo
source share