为什么我的 ScrollView/CATiledView 不能正确缩放?
我有一个由 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
找到了。使用
CGContextGetCTM(CGContextRef)
获取CGAffineTransform
,并使用a
(或b
)属性的值作为变焦。获取适当缩放的屏幕分辨率中的图像(将高度和宽度乘以缩放比例)。然后将该图像绘制到剪辑框中。Found it. Get the
CGAffineTransform
withCGContextGetCTM(CGContextRef)
, and use the value of thea
(orb
) 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.