tags:

views:

39

answers:

2

Hi!

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.
Each image is 512 x 512.

I feel that some kind of optimization is lacking here.

Can anyone help with something?
Thanks you all.

+1  A: 

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.

deanWombourne
This really helped to boost the speed, thanks!But even so, I find that google maps is so much more fluid than mine...How they do it??
Tsimmi
it's probably all down to dealing with the touches - on Google maps if you drag the map and let go, the map slides to a stop so that probably helps make it feel smoother. They will also pre-load some of the images - i.e. instead of just loading the 4 center ones, they will also load the 12 ssurrounding ones as well so they slide on seamlessly. they'll also load the images on a background thread and fade them on when they are loaded.
deanWombourne
+1  A: 

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

hotpaw2