我有一個包含大量註釋(8000+)的MapView。在所有註釋都可見的情況下,通過滾動地圖來降低性能。所以,當我在可見區域時,我有想法隱藏一些註釋。我在論壇中發現了this thread,但它不能解決我的問題。如何管理大量的MapViewAnnotations
我試圖通過編寫這段代碼
- (void)mapView:(MKMapView *)_mapView regionDidChangeAnimated:(BOOL)animated
{
NSSet *annoSet = [[NSSet alloc] initWithSet:[_mapView annotationsInMapRect:_mapView.visibleMapRect]];
NSMutableSet *annotationsSet = (NSMutableSet *)annoSet;
NSLog(@"Annos: %i", [annotationsSet count]);
if([annotationsSet count]>500)
{
for(MapViewAnnotation* annotation in annotationsSet)
{
[[_mapView viewForAnnotation:annotation] setHidden:YES];
}
}
}
這工作另一種解決方案,但手術後的MapView是全部癱瘓近,我有什麼可以改善?
編輯:
我的新代碼如下所示:
- (void)mapView:(MKMapView *)_mapView regionDidChangeAnimated:(BOOL)animated
{
NSSet *annoSet = [[NSSet alloc] initWithSet:[_mapView annotationsInMapRect:_mapView.visibleMapRect]];
//NSMutableSet *annotationsSet = (NSMutableSet *)annoSet;
NSLog(@"Annos: %i", [annoSet count]);
if([annoSet count]>500)
{
for(MapViewAnnotation* annotation in annoSet)
{
[[_mapView viewForAnnotation:annotation] setHidden:YES];
}
}
else if([annoSet count] <= 500)
{
for(MapViewAnnotation* annotation in annoSet)
{
[[_mapView viewForAnnotation:annotation] setHidden:NO];
}
}
}
,但我不希望隱藏在的visibleRect只是其中的所有註釋。 任何想法我怎麼能以有效的方式做到這一點?
我測試了我的代碼幾次,我幾乎可以確定我的MapView不是靠近故障。我想那樣,因爲我不能滾動它。滾動被阻止的原因是,我在無形註釋上點擊了太長的時間,以至於標註泡泡出現,並且在此狀態下無法滾動地圖 – user1895268