iPad 上的 MKMapView 渲染问题
我的问题仅出现在 iPad 上。 MKMapView 总是有未渲染的部分(下图右侧)。一旦我触摸这个窗口,地图视图就会很好地重新绘制自己。但它永远不会立即正确渲染。此问题出现在 iOS 4.2 以及 iOS 3.2 的模拟器和设备中。构造 MKMapView 的代码如下:
- (void)viewDidLoad {
[super viewDidLoad];
mapview = [[[MKMapView alloc] initWithFrame:CGRectMake(0,0,self.view.frame.size.width,230)] autorelease]; // because of apples bug
mapview.autoresizingMask = UIViewAutoresizingFlexibleWidth;
MKCoordinateSpan globe = MKCoordinateSpanMake(100, 100);
CLLocationCoordinate2D worldCenter; worldCenter.latitude = 42.032974; worldCenter.longitude =21.359375;
MKCoordinateRegion worldmap = MKCoordinateRegionMake(worldCenter, globe);
mapview.region = worldmap;
mapview.zoomEnabled = NO;
mapview.showsUserLocation = YES;
mapview.delegate = self;
NSRange theRange;
theRange.location = 1;
theRange.length = [annotations count]-1;
[mapview addAnnotations:[annotations subarrayWithRange:theRange]];
[self.view addSubview:mapview];
}
该问题仅在横向方向上表现出来。
更新
这是我触摸视图后它的跨越方式。
My problem occurs only on iPad. There is always unrendered portion of MKMapView(right side on the picture below). As soon as I touch this window the mapview repaints itself just fine. But it never renders correctly right away. This problem occures in iOS 4.2 as well as in iOS 3.2 in Simulator and the Device. The code that constructs MKMapView is right below:
- (void)viewDidLoad {
[super viewDidLoad];
mapview = [[[MKMapView alloc] initWithFrame:CGRectMake(0,0,self.view.frame.size.width,230)] autorelease]; // because of apples bug
mapview.autoresizingMask = UIViewAutoresizingFlexibleWidth;
MKCoordinateSpan globe = MKCoordinateSpanMake(100, 100);
CLLocationCoordinate2D worldCenter; worldCenter.latitude = 42.032974; worldCenter.longitude =21.359375;
MKCoordinateRegion worldmap = MKCoordinateRegionMake(worldCenter, globe);
mapview.region = worldmap;
mapview.zoomEnabled = NO;
mapview.showsUserLocation = YES;
mapview.delegate = self;
NSRange theRange;
theRange.location = 1;
theRange.length = [annotations count]-1;
[mapview addAnnotations:[annotations subarrayWithRange:theRange]];
[self.view addSubview:mapview];
}
The problem manifests itself only in Landscape orientation.
UPDATE
This is how it spans after I touched the view.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尽管如此,这是苹果的错误。在 iPad 横向模式下,您的经度跨度可能不足以覆盖地球 360 度。它应该随着缩放自动缩放,但事实并非如此。仅当您的 centerMap 恰好位于 0 度经度时,它才会正确自动缩放。诡异的。
解决方法:
Nonetheless it's Apple's bug. In iPad-landscape mode your longtitude span may not be enough to cover 360degree of the globe. it should autoscale with zoom, but it doesn't. it autozooms properly only if your centerMap is exactly at 0 degree longitude. Weird.
Workaround:
我对您的代码进行了快速测试并得到了相同的结果(这是我所期望的)。我仍然认为这不是地图本身的问题,而是您设置中心坐标和地图跨度的方式的问题。您试图以最大跨度将地图居中到左侧太远,并且地图填充整个屏幕并保持中心点的唯一方法是它自行拉伸,这是不可取的。如果将纬度和经度设置为 0,您将获得相同的视图,而不会丢失部分。
I did a quick test with your code and get the same result (which I expected). I still think it is not an issue with the map itself but with the way you are setting your center coordinates plus map span. You're trying to center the map too far to the left with max span and the only way for the map to fill the entire screen and maintain the center point would be for it to stretch itself, which is not desirable. If you set lat and long to 0 you get the same view without the missing part.