开发者

how to speed-up drawRect?

I'm coding a map app for iPhone, like Google Maps but with my own maps.

What I have so far is working, but sadly, slower than I would like.

I'm basically drawing the correct map tiles in each drawRect:

[image drawAtPoint:CGPointMake(x, y)];

X and Y are being calculated in each call to drawRect

( these calcs are not very expensive ).

The maximum number of images being drawn at a time is 4开发者_如何学C.

Each image is 512 x 512.

I feel that some kind of optimization is lacking here.

Can anyone help with something?

Thanks you all.


Why not create UIImageView objects for each tile?

INstead of drawing each image in drawRect, just move the UIIMageView to the correct position in layoutSubviews

The UIImageView will handle drawing when it needs to and will cache it's drawn rect. You're re-rendering each image every time drawRect is called.

The trade-off will probably be more memory consumption as you're making UIImageView objects but you can find a scheme to release ones that aren't being displayed if you need to.


Look for Apple's developer notes on using a tiled scrollview. It may automatically do what you want.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜