Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I tried to fix your code, however as you only seem to have posted half of it I couldn't get it working (Copy+pasting code results in lots of errors, let alone start performance tuning it).</p> <p>However there are some tips you can use to VASTLY improve performance.</p> <p>The first, and probably most noticeably, is -setNeedsDisplayInRect: rather then -setNeedsDisplay. This will mean that it only redraws the little rect that changed. For an iPad 3 with 1024*768*4 pixels that is a lot of work. Reducing that down to about 20*20 or less for each frame will <em>massively</em> improve performance.</p> <pre><code>CGRect rect; rect.origin.x = minimum(coordA.x, coordB.x) - (thickness * 0.5); rect.size.width = (maximum(coordA.x, coordB.x) + (thickness * 0.5)) - rect.origin.x; rect.origin.y = minimum(coordA.y, coordB.y) - (thickness * 0.5); rect.size.height = (maximum(coordA.y, coordB.y) + (thickness * 0.5)) - rect.origin.y; [self setNeedsDisplayInRect:rect]; </code></pre> <p>Another big improvement you could make is to only draw the CGPath for this current touch (which you do). However you then draw that saved/cached image in the draw rect. So, again, it is redrawn each frame. A better approach is to have the draw view being transparent and then to use a UIImageView behind that. UIImageView is the best way to display images on iOS.</p> <pre><code>- DrawView (1 finger) -drawRect: - BackgroundView (the image of the old touches) -self.image </code></pre> <p>The draw view would itself then only ever draw the current touch only the part that changes each time. When the user lifts their finger you can cache that to a UIImage, draw that over the current background/cache UIImageView's image and set the imageView.image to the new image.</p> <p>That final bit when combining the images involves drawing 2 full screen images into an off screen CGContext and so will cause lag if done on the main thread, instead this should be done in a background thread and then the result pushed back to the main thread.</p> <pre><code>* touch starts * - DrawView : draw current touch * touch ends * - 'background thread' : combine backgroundView.image and DrawView.drawRect * thread finished * send resulting UIImage to main queue and set backgroundView.image to it; Clear DrawView's current path that is now in the cache; </code></pre> <p>All of this combined can make a very smooth 60fps drawing app. However, views are not updated as quickly as we'd like so the drawing when moving the figure faster looks jagged. This can be improved by using UIBezierPath's instead of CGPaths.</p> <pre><code>CGPoint lastPoint = [touch previousLocationInView:self]; CGPoint mid = midPoint(currentPoint, lastPoint); -[UIBezierPath addQuadCurveToPoint:mid controlPoint:lastPoint]; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload