Question

I've got a UIScrollView with a (custom) UIView inside of it.

In my scrollViewDidScroll-method I'm calling

[myCustomView setNeedsDisplay];

This makes the scrolling noticeably slower, if I'm implementing the drawRect: method in my custom UIView - even if it's completely empty.

As soon as I delete the drawRect: method, it's smooth again.

I have absolutely no idea, why... anyone of you?

Was it helpful?

Solution

I hate drawrect too

"It's because of the way hardware-accellerated animation works in Cocoa.

If you don't have a custom drawRect method, the system caches the pixels for your view in video memory. When it needs to redraw them, it just blits the pixels onto the screen.

If you have a custom drawRect method, the system instead has to call your drawRect method to render the pixels in main memory, then copy those pixels into video memory, THEN draw the pixels to the screen for each an every frame. The docs say to avoid drawRect if you can.

I think main memory and video memory are shared on most/all iOS devices, but the system still has a lot more work to do when you implement a drawRect method for a view.

You would probably be better served to use an OpenGL layer and render to that with OpenGL calls, since OpenGL talks directly with the display hardware."

link to that quote: http://www.iphonedevsdk.com/forum/iphone-sdk-development/80637-drawrect-makes-scrolling-slow-uiscrollview.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top