0

It seems that the standard way to draw dots, lines, circles, and Bezier paths is to draw them in inside of drawRect. We don't directly call drawRect, but just let iOS call it and we can use [self setNeedsDisplay] to tell iOS to try to call drawRect when it can...

It also seems that we cannot rely on

[self setClearsContextBeforeDrawing: NO];

to not clear the background of the view before calling drawRect. Some details are in this question: UIView: how to do non-destructive drawing?

How about directly drawing on the screen -- without putting those code in drawRect. For example, in ViewController.m, have some code that directly draw dots, lines, circles on the screen. Is that possible?

Community
  • 1
  • 1
nonopolarity
  • 146,324
  • 131
  • 460
  • 740
  • Of course it is possile when you don't use UIKit drawing at all and instead draw using OpenGL ES or a higher level framework like Cocos2D. – Felix Apr 22 '12 at 11:03
  • it is? what about just using iOS frameworks? It maybe like Win32 able to draw anything when not in the redraw function (when any rectangle region got "invalidated") – nonopolarity Apr 23 '12 at 00:18
  • And do you have to rely on Cocos2D or OpenGL ES to do it? Frameworks from Apple's iOS won't do it? – nonopolarity Apr 24 '12 at 04:03

1 Answers1

1

Without having to drop into OpenGL, the closest you can do to get around the erasure is to convert the context as an image using something like CGBitmapContextCreateImage. From there, you can retain the image in memory (or write it to disk if necessary), and then when you redraw the view, you first draw this original image into the context and then overlay it with new content.

Jeremy Flores
  • 483
  • 4
  • 8