我正在开发一款iPhone应用程序,可以显示某些位置上有多个圆形叠加层的地图.当我添加超过6个圆圈时,我遇到严重的内存问题和崩溃,并且我缩小到足以让它们全部可见.当我放大以便只能看到2个圆圈时,一切都很好.当我删除MKOverlays时,一切正常.
谁认识到这种行为?
用于创建叠加层的代码.我将叠加层存储在NSMutableDictionary中以供将来参考(能够从地图中删除它们并防止双重叠加)
- (void)updateMarkersForZones:(NSArray *)zones {
NSLog(@"MapViewController: Update Markers");
// For each zone, show a marker
for (Zone* zone in zones) {
NSString *keyMarker = [NSString stringWithFormat:@"%d-marker", zone.id];
MKCircle *circle = [overlayCache objectForKey:keyMarker];
if (circle == nil) {
// draw the radius circle for the marker
double radius = MAX(zone.markerRadius * 1.0, 1.0);
circle = [MKCircle circleWithCenterCoordinate:zone.location radius:radius];
[mapView addOverlay:circle];
// store the circle in a cache for future reference
[overlayCache setObject:circle forKey:keyMarker];
}
}
}
Run Code Online (Sandbox Code Playgroud)
用于生成叠加视图的代码
#pragma mark …Run Code Online (Sandbox Code Playgroud)