2011-02-25 43 views
2

我的问题只发生在iPad上。 MKMapView总是存在未渲染部分(下图右侧)。只要我触摸这个窗口,mapview重新绘制自己就好了。但它永远不会马上呈现正确。在iOS 4.2以及模拟器和设备中的iOS 3.2中发生此问题。该构造的MKMapView的代码是正确的下面:在iPad上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]; 
} 

的问题表现只在横向方向。

Incorrect span UPDATE

这是怎么跨越后,我感动的看法。 Correct span

+0

貌似你试图中心与跨度过大的地图来填满整个屏幕的世界中心的地图?据我所见,在屏幕右侧没有地图“左”可供渲染 - 即这是世界末日:) - 因此,请尝试播放跨度值以查看它是否能解决您的问题。 – Rog 2011-02-25 23:07:34

+0

@Rog只要我触摸这个视图,它就呈现得很好。它总是有足够的世界观,因为它通过削减地球的高度来自动缩放。 – bioffe 2011-02-25 23:14:34

+1

当你触摸屏幕并重新渲染时,你在右侧看到了什么酷炫的东西?我只是试图在地图应用上进行最大缩小,右侧与上面张贴的内容相吻合,所以我很好奇!? – Rog 2011-02-25 23:27:32

回答

0

我用你的代码做了一个快速测试,并得到了相同的结果(我预期)。我仍然认为这不是地图本身的问题,而是您设置中心坐标和地图跨度的方式。你试图用最大跨度将地图居中放置在左边太远,地图填充整个屏幕并保持中心点的唯一方法就是让它自己伸展,这是不可取的。如果您将lat和long设置为0,您将获得相同的视图,而不会丢失部分。

1

尽管如此,它却是苹果的错误。在iPad横向模式下,您的长距可能不足以覆盖全球360度。它应该使用缩放自动缩放,但它不会。只有当你的centerMap恰好处于0度经度时,它才能正确地自动生成。奇怪的。

解决方法:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { 
    CLLocationCoordinate2D worldCenter; worldCenter.latitude = 42.032974; 
    worldCenter.longitude = UIDeviceOrientationIsLandscape(toInterfaceOrientation)? 0.0 : 21.359375; 
    mapview.centerCoordinate = worldCenter; 
}