2011-02-25 99 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; 
}