2010-07-30 10 views
6

मैं एक आईफोन ऐप पर काम कर रहा हूं जो कुछ स्थानों पर एकाधिक सर्कल ओवरले के साथ एक नक्शा दिखाता है। जब मैं 6 से अधिक मंडलियों को जोड़ता हूं तो मैं गंभीर स्मृति समस्याओं और क्रैश में भाग रहा हूं और मैं बहुत दूर ज़ूम आउट करता हूं कि वे सभी दिखाई दे रहे हैं। जब मैं ज़ूम इन करता हूं कि केवल 2 मंडल दिखाई दे रही हैं, तो सब ठीक है। जब मैं एमके ओवरलेज़ को हटा देता हूं, तो सब कुछ ठीक काम करता है।MKMapView पर एकाधिक 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]; 
     } 
    } 
} 

कोड ओवरले बार देखा गया है कि बनाता है

#pragma mark - 
#pragma mark MKMapViewDelegate 
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay{ 
    MKCircleView *circleView = [[[MKCircleView alloc] initWithCircle:overlay] autorelease]; 
    circleView.lineWidth = 1.0; 
    circleView.strokeColor = [UIColor redColor]; 
    return circleView; 
} 

कोड है कि रिलीज की दुकान ओवरले कैश

- (void)dealloc { 
    [overlayCache release]; 
    [mapView release]; 
    [super dealloc]; 
} 
+0

जिज्ञासु क्या आईओएस इस पर हो रहा है के संस्करण। आप उपकरणों में स्मृति खपत स्पाइक कहां देखते हैं? – Nick

+0

मैं आईओएस 4.0 चला रहा हूं। एमकेसीकल कक्षा को 4.0 में जोड़ा गया था। मैंने कुछ और परीक्षण किया और यह केवल आईफोन 3 जी पर गंभीर समस्याएं पैदा करता है। 3 जीएस और सिम्युलेटर ठीक काम करते हैं। मुझे उपकरणों में कोई स्पाइक्स नहीं दिख रहा है, जिससे इसकी जांच करना मुश्किल हो जाता है .. – rule

उत्तर

5

मैं वही बात देख रहा हूं। मैं मंडलियों के बजाय एमकेपोलाइन्स खींचना चाहता हूं, लेकिन मेरे पास बिल्कुल वही समस्या है। 1 लाइन ठीक काम करती है, लेकिन जब मैं कई जोड़ना शुरू करता हूं और इसके आस-पास के मानचित्र को स्थानांतरित करने का प्रयास करता हूं तो स्मृति चेतावनियों के साथ दुर्घटनाग्रस्त हो जाता है। मैं अपना कोड पेस्ट करता हूं, लेकिन यह लाइन के लिए उपरोक्त बदलते सर्कल के समान है।

संपादित करें: समस्या यह प्रतीत होती है कि प्रत्येक ओवरले एक नई कोर एनीमेशन परत बनाता है। यहां एक कामकाज है - https://devforums.apple.com/thread/48154?tstart=0 इसके अलावा, मेरा मानना ​​है कि यह एक ज्ञात बग है जिसे अगली रिलीज

संपादित करें: वर्कअराउंड - "यह एपीआई के साथ कोई समस्या नहीं है बल्कि कार्यान्वयन के लिए कोई समस्या नहीं है। मेरा सुझाव उन्हें मैन्युअल रूप से एक के रूप में मजबूत करने के लिए, पल के लिए एक समाधान

उदाहरण के लिए है इस तरीके से एक MultiPolygon और इसी दृश्य को लागू कर सकते हैं:। "

@interface MultiPolygon : NSObject <MKOverlay> { 
    NSArray *_polygons; 
    MKMapRect _boundingMapRect; 
} 

- (id)initWithPolygons:(NSArray *)polygons; 
@property (nonatomic, readonly) NSArray *polygons; 

@end 

@implementation MultiPolygon 

@synthesize polygons = _polygons; 

- (id)initWithPolygons:(NSArray *)polygons 
{ 
    if (self = [super init]) { 
     _polygons = [polygons copy]; 

     NSUInteger polyCount = [_polygons count]; 
     if (polyCount) { 
      _boundingMapRect = [[_polygons objectAtIndex:0] boundingMapRect]; 
      NSUInteger i; 
      for (i = 1; i < polyCount; i++) { 
       _boundingMapRect = MKMapRectUnion(_boundingMapRect, [[_polygons objectAtIndex:i] boundingMapRect]); 
      } 
     } 
    } 
    return self; 
} 

- (void)dealloc 
{ 
    [_polygons release]; 
    [super dealloc]; 
} 

- (MKMapRect)boundingMapRect 
{ 
    return _boundingMapRect; 
} 

- (CLLocationCoordinate2D)coordinate 
{ 
    return MKCoordinateForMapPoint(MKMapPointMake(MKMapRectGetMidX(_boundingMapRect), MKMapRectGetMidY(_boundingMapRect))); 
} 

@end 



@implementation MultiPolygonView 

- (CGPathRef)polyPath:(MKPolygon *)polygon 
{ 
    MKMapPoint *points = [polygon points]; 
    NSUInteger pointCount = [polygon pointCount]; 
    NSUInteger i; 

    if (pointCount < 3) 
     return NULL; 

    CGMutablePathRef path = CGPathCreateMutable(); 

    for (MKPolygon *interiorPolygon in polygon.interiorPolygons) { 
     CGPathRef interiorPath = [self polyPath:interiorPolygon]; 
     CGPathAddPath(path, NULL, interiorPath); 
     CGPathRelease(interiorPath); 
    } 

    CGPoint relativePoint = [self pointForMapPoint:points[0]]; 
    CGPathMoveToPoint(path, NULL, relativePoint.x, relativePoint.y); 
    for (i = 1; i < pointCount; i++) { 
     relativePoint = [self pointForMapPoint:points[i]]; 
     CGPathAddLineToPoint(path, NULL, relativePoint.x, relativePoint.y); 
    } 

    return path; 
} 

- (void)drawMapRect:(MKMapRect)mapRect 
      zoomScale:(MKZoomScale)zoomScale 
      inContext:(CGContextRef)context 
{ 
    MultiPolygon *multiPolygon = (MultiPolygon *)self.overlay; 
    for (MKPolygon *polygon in multiPolygon.polygons) { 
     CGPathRef path = [self polyPath:polygon]; 
     if (path) { 
      [self applyFillPropertiesToContext:context atZoomScale:zoomScale]; 
      CGContextBeginPath(context); 
      CGContextAddPath(context, path); 
      CGContextDrawPath(context, kCGPathEOFill); 
      [self applyStrokePropertiesToContext:context atZoomScale:zoomScale]; 
      CGContextBeginPath(context); 
      CGContextAddPath(context, path); 
      CGContextStrokePath(context); 
      CGPathRelease(path); 
     } 
    } 
} 

@end 
+0

धन्यवाद, मैं उस काम को चारों ओर कोशिश करूंगा! – rule

+1

क्या यह बग कभी आईओएस 4.x रिलीज में तय किया गया था? –

+2

हां, उन्होंने इसे 4.1 – clarky

संबंधित मुद्दे