views:

615

answers:

2

My app is doing some pretty but heavy weight core animations during scrolling. Sometimes it crashes due to bad performance. So I need some way to find out if there is enough capability to make the animations, and if not, I just leave them away. Best way would be if I could ask the system how busy it is.

UPDATE: I mean especially Core Animation.

+2  A: 

I wouldn't do that. If your app crashes, it's to heavy. You could run your app with some instruments to see where your bottlenecks are.

So, without trying to sound too harsh, your best way is to rewrite some parts in order to make you app run on an iPhone at all times.

Kriem
What would you not do particularly?
Thanks
Asking the system how busy it is in order to adjust the load.
Kriem
Is this: http://stackoverflow.com/questions/901308/are-there-any-tools-or-good-techniques-to-find-out-where-the-performance-bottlene in respond to this?
Kriem
+3  A: 

By animation, do you mean frames that play after one another (like an animated GIF) or some CoreAnimation (OpenGL) effect that is moving polygons with mapped textures around?

If it's the former, I'd really consider some way of optimizing the animation or eliminating it in all cases.

If it's the latter, I'd do some deeper digging into the source of the problem. Core Animation under normal circumstances will drop frames in order to keep from getting into situations like this in the first place.

In either case case you might consider loading the texture assets a little earlier. I have had some trouble in my apps with animation methods that take a UIImage parameter when I created the UIImage in the function call. Preloading the asset a little earlier in my code took care of the problem nicely.

As an example:
BAD

[[UIImage imageNamed:@"checkmark.png"] drawAtPoint:p];

BETTER

//declared at top of class
static UIImage *checkmark = nil;

in init:

checkmark = [UIImage imageNamed:@"checkmark.png"];

in drawRect:

[checkmark drawAtPoint:p];

You would need to adapt this technique to your particular situation. In my case, checkmark is used often, and it quite small, I don't mind dedicating the memory to it permanently.

I wonder if your crashes could be fixed by making sure the assets were ready to be used by the application.

mmc