Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change iphone CATiledLayer fadeDuration?

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.

like image 443
nico_h Avatar asked Jul 02 '09 10:07

nico_h


1 Answers

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]

like image 66
esad Avatar answered Oct 16 '22 16:10

esad