提高CATiledView的性能

时间:2010-07-01 16:47:53

标签: iphone performance ipad catiledlayer

我一直在寻找一种提高CATiledView性能的方法。视图占据了整个屏幕(我有一个iPad和iPhone版本)。目前,瓷砖需要大约12秒才能完全填满(两台设备都需要12秒)。我已经看到其他应用程序使用CATiledView,它需要花费更少的时间来填充瓷砖。

我一直使用的图像是1 7000x5000 JPEG。我已经尝试将图像缩小到5500px并且加载时间没有变化,这让我相信它是我的代码的问题,如下所示:

更新:我尝试减少图像的大小(超过一半)并且没有区别我可以告诉。

-(void) loadMap{

        ...
        UIImage *tempImage = [UIImage imageWithData:data];
        self.image = tempImage;

        CGRect pageRect = CGRectMake(0,  0,  image.size.width, image.size.height);

        CATiledLayer *tiledLayer = [CATiledLayer layer];
        tiledLayer.anchorPoint = CGPointMake(0.0f, 1.0f);
        tiledLayer.delegate = self;
        tiledLayer.levelsOfDetail = 6; 
        tiledLayer.levelsOfDetailBias = 0;
        tiledLayer.bounds = pageRect; 
        tiledLayer.transform = CATransform3DMakeScale(1.0f, -1.0f, 0.3f);
        CGRect imageRect  = CGRectMake(0, 0, image.size.width, image.size.height);
        myContentView = [[UIView alloc] initWithFrame:imageRect];
        [myContentView.layer addSublayer:tiledLayer];

        UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:self.chartView.frame];
        scrollView.delegate = self;
        scrollView.contentSize = pageRect.size;
        scrollView.minimumZoomScale = .2;   
        scrollView.maximumZoomScale = 1; 

        scrollView.clipsToBounds = YES;
        [scrollView addSubview:myContentView];
        [self.chartView addSubview:scrollView];
        scrollView.zoomScale = .2;


}

    - (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx
    {


        CGRect imageRect = CGRectMake (0.0, 0.0, image.size.width, image.size.height);
        CGContextDrawImage (ctx, imageRect, [image CGImage]);

    }

1 个答案:

答案 0 :(得分:1)

我在今年的WWDC视频中找到了答案和示例代码。如果你有访问权限,请查看它我认为是104,称为滚动视图