开发者

The problem about fps

I have created a project . and there are three groups of images need to display , and every group has 5 images . In the app , the image will be changed once per 0.2 seconds . and the size of the image is only 30*30 , so there are about 80 images on screen , they all have the animation . But when I test this , I feel the fps seems become 0.8 seconds , it was very s开发者_如何转开发low .

All the images are drawn in ONE UIView . I use [image drawInRect:] in the method -(void)drawRect . So is there any suggestions for me to make the fps more faster ?


Have you tried putting 80 UIImageViews on the screen? If you only set the new image on each of these when required, you should see an improvement.

The reason is that each UIView has its own CALayer, which is copied to the graphics memory when required. It's quite slow to copy across a pixel (but once it's there it's cached), so if you only update one 30x30 tile at a time you should see better performance than if you were constantly updating the screen.

You could of course manually manage 80 CALayers within a single UIView but that would be much more difficult than using 80 UIImageViews.

Any time you override -(void)drawRect you're likely to hurt performance a lot, because of the way CALayers interact with graphics memory. The iPhone's Quartz graphics system is optimised for having lots of static layers than can then be manipulated with graphics commands (transform, opacity etc).


Profile. Use the Instruments application to find out which part of your code is running slowest, and then see whether you can either speed it up or avoid calling it so often. For example: do you really need to re-draw all of the images all of the time? Could you replace some Cocoa Touch code with the same behaviour using Core Animation or OpenGL ES?

Iterate. Once you've made a tweak, profile again. Did it get better? If it did, then look for the next thing to speed up. If it didn't, decide whether it's at all helpful or should be reverted.


well, every time you draw something... it's a work... you probably can get better performances just loading all your images at the beginning and then just swap them on screen (with hide/show your UIImageView), if images are so small you won't have memory problems...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜