我有一个由 CATiledLayer 支持的 UIScrollView。该层正在从服务器中提取切片并显示它们以响应调用时的请求drawLayer:inContext
。这是它的样子:
-(void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx{
ASIHTTPRequest *mapRequest;
WMSServer *root = self.mapLayer.parentServer;
while(root == nil){
root = self.mapLayer.parentLayer.parentServer;
}
//Get where we're drawing
CGRect clipBox = CGContextGetClipBoundingBox(ctx);
double minX = CGRectGetMaxY(clipBox);
double minY = CGRectGetMinX(clipBox);
double maxX = CGRectGetMinY(clipBox);
double maxY = CGRectGetMaxX(clipBox);
//URL for the request made here using the min/max values from above
NSURL *url = [[NSURL alloc] initWithString:path];
mapRequest = [ASIHTTPRequest requestWithURL:url];
[url release];
[mapRequest startSynchronous];
//Wait for it to come back...
//Turn the Data into an image
NSData *response = [mapRequest responseData];
//Create the entire image
CGDataProviderRef dataProvider = CGDataProviderCreateWithCFData((CFDataRef)response);
CGImageRef image = CGImageCreateWithPNGDataProvider(dataProvider, NULL, true, kCGRenderingIntentDefault);
CGDataProviderRelease(dataProvider);
//Now paint the PNG on the context
CGContextDrawImage(ctx, clipBox, image);
}
当我放大时会出现问题。图块的大小(如clipBox
矩形所示)缩小了,如果是 32 x 32 像素,则 URL 的格式正确为 32 像素,但屏幕上显示的内容会缩放直到默认的 tileSize(在这种情况下为 128 x 128 像素)。有什么方法可以让图层正确绘制这些图像。