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
The maximum number of images being drawn at a time is 4开发者_如何学C.
Each image is512 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.
精彩评论