views:

1922

answers:

2

Hi StackOverflowers

I am working on an iphone application that displays tiled maps. I am currently using a CATiledLayer in a UIScrollView :

     MyTiledDelegate *delegate=[[MyTiledDelegate alloc] initWithMapLayer:map];
     tileLayer = [CATiledLayer layer];
     tileLayer.delegate = delegate;
     [scrollView.layer addSublayer:tileLayer];
     [tileLayer setNeedsDisplay];

I wrote and set my own delegate which implements the draw layer method like so :

- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx{
    CGRect rect =CGContextGetClipBoundingBox(ctx);
    CGFloat x = fabs(round(rect.origin.x/tileSize));
    CGFloat y = fabs(round(rect.origin.y/tileSize));

    Tile *tile = [map getTileForMapZoom:z x:x y:y];
    CGImageRef img=[tile getRealImage];
    CGContextDrawImage(
        ctx,
        CGRectMake(tile.x*tileSize,tile.y*tileSize, tileSize,tileSize) , 
        img);
    }//edited for brevity

I am annoyed by the default behavior of the CAtiledLayer to fadein after the tile is drawn. Also, sometimes the fadein is not complete (it stops at 90 or 95% opacity).

How can i change or (preferably) remove the fadein animation ?

I played with the speed and duration properties of my CATiledLayer instance, to no avail. I don't set any animation on the tiledLayer. the [tiledLayer removeAllAnimation] does not change anything either.

Thanks for any pointers.

+1  A: 

Try subclassing and overriding the +fadeDuration accessor on the layer.

Ben Stiglitz
+3  A: 

You should subclass the CATiledLayer and return fadeDuration of 0 to disable fade-in:

@interface FastCATiledLayer : CATiledLayer
@end

@implementation FastCATiledLayer
+(CFTimeInterval)fadeDuration {
  return 0.0;
}
@end

I also had the problem with fade in animation not completing, what helped was to set the background color of the view to [UIColor clearColor]

esad
Make sure to replace `fastDuration` with `fadeDuration` in the code.
lucius
Corrected, thanks!
esad
The "not completion" problem appeared to go away when I set the fadeDuration to 0.
David Dunham