地圖上有註釋(可視標籤)。當用戶在地圖中縮放(放大或縮小)時,會調用名爲'regionDidChangeAnimated'的方法。每次完成時,我嘗試使用快速枚舉來查看哪些註記對象當前與地圖上的哪些註記對象相交。這是因爲我使用的是YandexMapKit(不是蘋果標準的MapKit),並且沒有太多關於如何以其他方式完成這些任務的文檔或示例。下面是唯一的代碼,我能想出這麼遠,但它最終崩潰的應用程序:比較兩個數組值CGRectIntersectsRect
NSArray *allAnnotations = [_mapView annotations];
// Check for intersecting annotation bounds.
for (RBMapAnnotation *annotation1 in allAnnotations)
{
YMKPinAnnotationView *pinView1 = (YMKPinAnnotationView *)annotation1; // Still returns as 'RBMapAnnotation'.
for (RBMapAnnotation *annotation2 in allAnnotations)
{
YMKPinAnnotationView *pinView2 = (YMKPinAnnotationView *)annotation2;
if (CGRectIntersectsRect([pinView1 convertRect:pinView1.bounds toView:nil], [pinView2 convertRect:pinView2.bounds toView:nil]))
{
NSLog(@"Interesction between %@ and %@", annotation1.offer.name, annotation2.offer.name);
//[annotationsToUpdate addObject:annotation];
}
}
}
請幫我出這一點。我試圖獲得的是,如果任何註釋在視覺上都在地圖上相交,那麼我將它們都刪除並用1個註釋替換它們。
@Alex for適用於符合NSFastEnumeration的任何對象。 NSEnumerator符合NSFastEnumeration。 –
我將其更改爲標準'[allAnnotations reverseObjectEnumerator]'爲'allAnnotations'。但它仍然崩潰。並不是說它應該有所作爲。 – Krekin
提供有關崩潰的詳細信息。哪條線完全崩潰,錯誤信息是什麼? – rmaddy