This is my first post here – but I’ve been a reader for a long time. Thank you so much for this site! 🙂
I am currently working on a port of my XNA-based 2D engine from WP7 to iOS (5). I would prefer not to use OpenGL directly, because I prefer to invest my time more in gameplay than in technique. So I would be very happy to get an answer not involving OpenGL (directly).
The problem:
When I add an UIImageView to another UIView, there is a short delay before the UIImageView gets drawn. I assume, this is due to the caching the UIView-class performs before converting everything internally to OpenGL then drawing.
What I want:
Tell the UIView (superview) to perform all neccessary calculations for all subviews and then draw them all at once.
Currently the behaviour I observe ist: Calculate uiimageview_1, draw uiimageview_1, calculate uiimageview_n, draw uiimageview_n, …
Dummycode of what I want:
// put code here to tell superview to pause drawing
for (int i = 0; i < 400; i ++)
{
add UIImageView[i] to superview;
}
// put code here to tell superview to draw now
Possible workaround (but coming from C# & Windows, I have no idea how to implement it efficiently in Objective-C on iOS) – I am afraid that this code is inefficient because large blocks of RAM had to be transferred (per frame!) on retina displays at native resolution:
for (int i = 0; i < 400; i ++)
{
add UIImageView[i] to superview;
}
// put code here to get a bitmap in ram from superview
// return bitmap and draw it in a view for the scenery/canvas
Any help on how to approach this “popping”-problem would be highly appreciated.
Thanks
Answering this will be a bit tricky. The exact behavior of Cocoa Touch is undocumented (an ‘implementation detail’ says Apple), so recommendations can only be given based on guessing and experience.
Instead of working with UIViews, you might want to try CoreAnimation. It abstracts 2D drawing and compositing operations without the overhead of a UI framework such as UIKit. It also much easier to use than programming OpenGL directly. UIKit uses CoreAnimation to do it’s drawing, but augments it in many ways. This ‘augmentation’ might be exactly the reason why you’re hitting performance problems.
Have a look at the tutorial and judge for yourself.