1

Does anyone have any tricks for improving the performance of CATiledLayer on a retina display?

This post: CATiledLayer in iPad retina simulator yields poor performance

implies that there are issues with the simulator, but I'm noticing poor performance on the actual device as well. It's a pretty obvious issue since it's loading larger tiles sooner on the retina display. The only thing I can thing of is to reprocess the tiled images with more levels of detail.

I do one little trick:

    CGFloat scale = CGContextGetCTM(context).a / self.contentScaleFactor;

when calculating the scale, but that doesn't seem to be enough to deal with the poor performance.

Community
  • 1
  • 1
Ralphleon
  • 3,968
  • 5
  • 32
  • 34
  • Just confirming that I'm seeing the same issue on the hardware. CATiledLayer seems to work much better on my iPad 2 than on my iPad 3. Not sure if that's due to a bug in my code, or some underlying problem. – Greg Maletic Mar 19 '12 at 23:55
  • Override `-(void)didMoveToWindow { [super didMoveToWindow]; self.contentScaleFactor = 1; }`. The short story is that CATiledLayer already works based on screen *pixels* (not "points"). A little more discussion [here](http://markpospesel.wordpress.com/2012/04/03/on-the-importance-of-setting-contentscalefactor-in-catiledlayer-backed-views/) – tc. Oct 29 '12 at 16:17

1 Answers1

1

On my tiling view:

- (id)initWithImageName:(NSString *)name size:(CGSize)size
{

    if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] == YES && [[UIScreen mainScreen] scale] == 2.00) {

        size = CGSizeMake(size.width*2, size.height*2);

    }

    if ((self = [super initWithFrame:CGRectMake(0, 0, size.width, size.height)])) {

        CATiledLayer *tiledLayer = (CATiledLayer *)[self layer];

        tiledLayer.levelsOfDetail = 4;
        if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] == YES && [[UIScreen mainScreen] scale] == 2.00) {

            tiledLayer.tileSize = CGSizeMake(512, 512);
        }

    }

    return self;
}

This got the iPad 3 working like the iPad 2 for me. If you're doing anything else, like overlaying data etc then you may have to do some more wrangling. Effectively this just doubles the size of your content, and the size of your tiles, negating the effects of the retina display.

You may also want to change your max and min zoomScales for the retina

Brodie
  • 3,526
  • 8
  • 42
  • 61