Optimizing a drawing (with finger touches) application for iPhone SDK

前端 未结 5 1426
梦如初夏
梦如初夏 2021-02-04 19:35

I\'m writing an application that uses your finger to draw simple diagrams. I have it working for the most part but now I\'m trying to optimize its performance. When the user swi

相关标签:
5条回答
  • 2021-02-04 19:44

    Have you tried this?

    http://developer.apple.com/library/ios/#samplecode/GLPaint/Introduction/Intro.html#//apple_ref/doc/uid/DTS40007328-Intro-DontLinkElementID_2

    0 讨论(0)
  • 2021-02-04 19:52

    Another approach is to interpolate the curve between the sample points. When the finger drag starts, begin collecting sample points. As the number of points increase, redraw the line. With two points, draw a straight line, with three or more draw a curve. You can re-start the process when two points are sampled that lie within a defined distance. This would allow you to draw two arcs (like a 'm') in one motion - you naturally pause in the middle as you change direction, possibly long enough for two or more samples.

    0 讨论(0)
  • 2021-02-04 19:59

    drawRect gets called on the main thread. But you don't have to do this. You can use the main thread to collect UI events and do the drawing on a background thread. The background thread gets notified whenever there are new touches and starts a drawing operation in its own CGBitmapContext. Then you create a CGImage and hand it over to the View: view.layer.contents = drawingImage.

    If you need even more performance, consider drawing using OpenGL.

    0 讨论(0)
  • 2021-02-04 20:02

    I tried adding

    CGContextSetLineJoin(UIGraphicsGetCurrentContext(), kCGLineJoinRound);
    

    but this did nothing. Looks like we'll have to figure out bezier curves

    0 讨论(0)
  • 2021-02-04 20:07

    Aloo, did you have find a solution to his as I've got the same problem. I also found agreat tutorial http://www.ipodtouchfans.com/forums/showthread.php?t=132024 but it also has the same problem that if you draw fast, say a circle, the drawing isn't very smooth. It;s almost like the iPhone just can't keep up, unfortunately this has to use the core graphics stuff.

    0 讨论(0)
提交回复
热议问题