为什么我的ScrollView / CATiledView没有正确缩放?

时间:2010-06-07 19:56:20

标签: iphone objective-c cocoa uiscrollview catiledlayer

我有一个由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像素,则为32像素正确形成URL,但是屏幕上显示的内容扩展到默认的tileSize(在这种情况下为128 x 128像素)。是否有某种方法可以让图层正确绘制这些图像。

1 个答案:

答案 0 :(得分:0)

找到它。获取CGAffineTransform CGContextGetCTM(CGContextRef),并使用a(或b)属性的值作为缩放。在适当缩放的屏幕res中获取图像(通过缩放倍增高度和宽度)。然后将该图像绘制到剪辑框中。