为什么我的 ScrollView/CATiledView 不能正确缩放?

发布于 2024-09-04 14:49:49 字数 1490 浏览 9 评论 0原文

我有一个由 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 像素)。有什么方法可以让图层正确绘制这些图像。

I have a UIScrollView backed by a CATiledLayer. The layer is pulling tiles from a server and displaying them in response to what is requested when drawLayer:inContext is called. Here's what it looks like:

-(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);
}

The problem occurs when I zoom in. The size of the tiles (as indicated by the clipBox rectangle) shrinks down, and if it's at say, 32 by 32 pixels, the URL is properly formed for 32pixels, but what is displayed on the screen scaled up to the default tileSize (128 by 128 pixels in this case). Is there some way I can get the layer to properly draw these images.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一曲琵琶半遮面シ 2024-09-11 14:49:49

找到了。使用 CGContextGetCTM(CGContextRef) 获取 CGAffineTransform,并使用 a(或 b)属性的值作为变焦。获取适当缩放的屏幕分辨率中的图像(将高度和宽度乘以缩放比例)。然后将该图像绘制到剪辑框中。

Found it. Get the CGAffineTransform with CGContextGetCTM(CGContextRef), and use the value of the a (or b) property as the zoom. Get the image in a screen res that is the zoomed appropriately (multiply the height and width by the zoom). Then draw that image into the clip box.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文