Yes. Don't use -drawRect: . It's a long and complicated reason why, but basically when UIKit sees that you've implemented -drawRect: in your UIView subclass, rendering goes through the really slow software-based rendering path.
When you draw with CALayer objects and composite views, you can get hardware accelerated graphics, which can make your app FAR more performant.
Up vote 1 down vote favorite share g+ share fb share tw.
In my application, I have a UIViewController with a subclassed UIView (and several other elements) inside of it. Inside of the UIView, called DrawView, in my drawRect: method, I draw a table grid type thing, and plot an array of CGPoints on the grid. When the user taps on the screen, it calls touchesBegan:withEvent: and checks to find the closest point on the grid to the touch, adds a point to the array that the drawRect: method draws points from, and calls self setNeedsDisplay.
As the user moves their finger around the screen, it checks to see if the point changed from the last location, and updates the point and calls self setNeedsDisplay as necessary. This works great in the Simulator. However, when run on a real iPhone, it runs very slowly, when you move your finger around, it lags in drawing the dot.
I have read that running calculations for where to place the points in a different thread can improve performance. Does anyone have experience with this that knows this for a fact? Any other suggestions to reduce lag?
Objective-c ios core-graphics drawrect link|improve this question edited Aug 9 '11 at 21:19 asked Aug 9 '11 at 5:10Josh Sherick45511 97% accept rate.
Yes. Don't use -drawRect:. It's a long and complicated reason why, but basically when UIKit sees that you've implemented -drawRect: in your UIView subclass, rendering goes through the really slow software-based rendering path.
When you draw with CALayer objects and composite views, you can get hardware accelerated graphics, which can make your app FAR more performant.
Great answer. But how would you do that? User different view each with a layer or one view with multiple sublayers?
– Sandro Meier Aug 9 '11 at 7:21 @Sandro either would work, but I would probably use UIView objects instead of CALayers, because that leaves the possibility of attaching gesture recognizers, dealing with ObjC types instead of CF types (UIImage vs CGImageRef, etc)... – Dave DeLong Aug 9 '11 at 13:26 Thanks. I'm kind of newish and I have absolutely no idea what CALayer objects or composite views are. I found Apple's documentation on CALayer, but are there any other tutorials or documentation that you recommend learning about these things, and how to use them to draw with?
– Josh Sherick Aug 9 '11 at 21:17 @josherick By "composite views", I mean "add views as subviews of other views". You're compositing them together, i.e. Layering them on top of each other.
("composite" is being used as a verb, not an adjective) – Dave DeLong Aug 9 '11 at 22:10 wait, really? That seems like it would take a lot of memory, drawing a grid out of UIViews. And how would I draw lines connecting the points?
Or even a circle (point)? – Josh Sherick Aug 9 '11 at 23:19.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.