我一直在寻找一种方法来提高我的 CATiledView 的性能。该视图几乎占据了整个屏幕(我有 iPad 和 iPhone 版本)。目前,瓷砖完全填充大约需要 12 秒(两种设备上都需要 12 秒)。我已经看到其他应用程序使用 CATiledView 并且填充图块所需的时间要少得多。
我一直使用的图像是 1 7000x5000 JPEG。我尝试将图像缩小到 5500 像素,并且加载时间没有变化,因此我相信这是我的代码有问题,如下所示:
更新:我尝试减小图像的大小(减少一半以上),我可以说没有区别。
-(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]);
}