Iphone 屏幕外的MKMapView在3.2和4.0中的行为不同

Iphone 屏幕外的MKMapView在3.2和4.0中的行为不同,iphone,ipad,mapkit,iphone-sdk-3.2,ios4,Iphone,Ipad,Mapkit,Iphone Sdk 3.2,Ios4,在3.1中,我一直在使用“屏幕外”MKMapView创建地图图像,在向用户展示之前,我可以旋转、裁剪等。在3.2和4.0中,这种技术不再适用。下面是一些说明问题的代码,然后是我的理论 // create map view _mapView = [[MKMapView alloc] initWithFrame:CGRectMake(0, 0, MAP_FRAME_SIZE, MAP_FRAME_SIZE)]; _mapView.zoomEnabled = NO;

在3.1中,我一直在使用“屏幕外”MKMapView创建地图图像,在向用户展示之前,我可以旋转、裁剪等。在3.2和4.0中,这种技术不再适用。下面是一些说明问题的代码,然后是我的理论

     // create map view

     _mapView = [[MKMapView alloc] initWithFrame:CGRectMake(0, 0, MAP_FRAME_SIZE, MAP_FRAME_SIZE)];
     _mapView.zoomEnabled = NO;   
     _mapView.scrollEnabled = NO;
     _mapView.delegate = self;    
     _mapView.mapType = MKMapTypeSatellite;

     // zoom in to something enough to fill the screen
     MKCoordinateRegion region;    
     CLLocationCoordinate2D center = {30.267222, -97.763889};

     region.center = center;    
     MKCoordinateSpan span = {0.1, 0.1 };    
     region.span = span;    
     _mapView.region = region;

     // set scrollview content size to full the imageView  
     _scrollView.contentSize = _imageView.frame.size;

     // force it to load

#ifndef __IPHONE_3_2

     // in 3.1 we can render to an offscreen context to force a load    
     UIGraphicsBeginImageContext(_mapView.frame.size);    
     [_mapView.layer renderInContext:UIGraphicsGetCurrentContext()];
     UIGraphicsEndImageContext();

#else

     // in 3.2 and above, the renderInContext trick doesn't work...    
     // this at least causes the map to render, but it's clipped to what appears to be    
     // the viewPort size, plus some padding    
     [self.view addSubview:_mapView];          

#endif
当地图加载完毕后,我会抓拍它的图片并将其填充到我的滚动视图中

- (void)mapViewDidFinishLoadingMap:(MKMapView *)mapView {    
     NSLog(@"[MapBuilder] mapViewDidFinishLoadingMap");

     // render the map to a UIImage
     UIGraphicsBeginImageContext(mapView.bounds.size);

     // the first sub layer is just the map, the second is the google layer, this sublayer structure might change of course

     [[[mapView.layer sublayers] objectAtIndex:0] renderInContext:UIGraphicsGetCurrentContext()];

     // we are done with the mapView at this point, we need its ram!    
     _mapView.delegate = nil;     

     [_mapView release];
     [_mapView removeFromSuperview];    
     _mapView = nil;

     UIImage* mapImage = [UIGraphicsGetImageFromCurrentImageContext() retain];
     UIGraphicsEndImageContext();     

     _imageView.image = mapImage;
     [mapImage release], mapImage = nil;  
}
第一个问题是,在3.1中,渲染到上下文会触发贴图开始加载。这在3.2、4.0中不再有效。我发现触发加载的唯一方法是将地图临时添加到视图中(即使其可见)。问题是贴图只渲染到屏幕的可见区域,加上一点填充。框架/边界很好,但它似乎“有帮助地”优化了加载,将平铺限制在屏幕上或屏幕附近可见的平铺上


你知道如何强制地图以全尺寸加载吗?还有其他人有这个问题吗?

你不应该在这里发布关于4.0的文章……3.2完全是离题的,但这很聪明。但是,为什么不直接使用静态地图API呢?存在商业限制和许可证问题。相信我,那会容易得多。你找到解决这个问题的方法了吗?我似乎遇到了同样的问题,并考虑在iOS 4上使用MKOverlay。但这就遗漏了3.2。。MKOverlay-ref:Update:我通过将OpenGL视图覆盖在MKMapView上解决了这个问题。iOS4似乎可以很好地处理OpenGL/UIFramework混合应用程序。虽然没有完全回答你最初的问题,但我认为其他人可能会发现这些信息很有用。此外,我还向苹果提交了一份bug报告,地址是bug ID#8234305/radr://problem/8234305