CATiledLayer in iPad retina simulator yields poor performance

后端 未结 4 1382
庸人自扰
庸人自扰 2020-12-23 08:37

I\'m hoping maybe this is just an issue with the simulator but of course it has me worried since I have already submitted my retina capable apps and there\'s no way to test

4条回答
  •  轮回少年
    2020-12-23 09:08

    The performance on iPad3 of all TiledLayers is worse than on iPad2 - that's also visible in the GoogleMaps app.

    However, the best performance you get by adding the following changes to your UIView class that uses CATiledLayer

    - (id)initWithFrame:(CGRect)frame tileSize:(CGSize)tileSize
    {
        self = [super initWithFrame:frame];
        if(self)
        {
            CATiledLayer *animLayer = (CATiledLayer *) self.layer;
            animLayer.levelsOfDetail = 5;
            animLayer.levelsOfDetailBias = 3;
            animLayer.tileSize = tileSize;
    
            // adjustments for retina displays
            if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] == YES && [[UIScreen mainScreen] scale] == 2.00)
            {
                animLayer.contentsScale = 1.0;
                self.contentScaleFactor = .5;
                animLayer.shouldRasterize = NO;
                animLayer.levelsOfDetailBias ++;
            }
        }
        return self;
    }
    
    - (void)layoutSubviews
    {
        [super layoutSubviews];
        if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] == YES && [[UIScreen mainScreen] scale] == 2.00)
        {
            self.contentScaleFactor = .5;
        }
    }
    

    There are other options to achieve the same result visually ie increasing tileSize but the performance will be much worse.

提交回复
热议问题