IPhone: no way to draw on screen outside of drawRect?

Is there a way to draw on the iPhone screen (on a UIView in a UIWindow) outside of this drawRect () method? If so, how do I get the graphics context?

The graphic guide mentions the NSGraphicsContext class, but the corresponding chapter looks like a blind copy / paste from Mac OS X documents, and there is no such class in the iPhone SDK.

EDIT: I'm trying to change the contents of a view in a touch event handler - highlight the affected visual element. On Windows, I would use GetDC () / ReleaseDC () rather than the full InvalidateRect () / WM_PAINT loop. Trying to do the same here. The ordering of active (tangible) elements as subzones is a huge penalty for performance, since there are about a hundred of them.

+4
source share
2 answers

Not. Drawing is drawRect: (or CALayer). Even if you can paint elsewhere, it will smell like code (like on a Mac). Any other code should simply update your model state, and then set itself up as a mapping need.

When you need to display, moving the display code to another location will not speed it up. If you do not need a display (and therefore it was not set as necessary for display), the display code will not work if it is in drawRect:

I am trying to change the contents of a view in a touch event handler - highlight the affected visual element. On Windows, I would use [Windows code] .... Organizing active (tangible) elements as subzones is a huge performance penalty, since there are about a hundred of them.

It seems that Core Animation might be more suitable for this.

+5
source

I don't think the trick will be able to draw outside of drawRect ... but to get the current graphics context, all you do is CGContextRef c = UIGraphicsGetCurrentContext (); hope this helps.

0
source

Source: https://habr.com/ru/post/1309680/


All Articles