MKOverlay иногда исчезает

У меня есть два варианта наложения на моей карте: MKCircleOverlay и MKPolygonOverlay. Первый с переменным радиусом, управляемый через UISlider. Последний настраивается в зависимости от количества и положения углов. Если я очень быстро изменяю радиус круг (уменьшите значение UISlider) иногда у меня пропадает оверлей (круг) и после этого многоугольник больше не рисуется (конечно круг тоже). Приложение не вылетает. Что это может быть?

Вот код, который я использую:

- (IBAction) addCircle:(id)sender
{
slider.hidden = NO;
slider.transform = CGAffineTransformMakeRotation(M_PI*(-0.5));

_longPressRecognizer= [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)];
_longPressRecognizer.minimumPressDuration = 1.0; 

[mapview addGestureRecognizer:_longPressRecognizer];
[_longPressRecognizer release];
}

- (void)handleLongPress:(UIGestureRecognizer *)gestureRecognizer
{
if (gestureRecognizer.state != UIGestureRecognizerStateBegan)
    return;
CGPoint touchPoint = [gestureRecognizer locationInView:mapview];    
CLLocationCoordinate2D touchMapCoordinate = [mapview convertPoint:touchPoint toCoordinateFromView:mapview];

MKPointAnnotation *pa = [[MKPointAnnotation alloc] init];
pa.coordinate = touchMapCoordinate;
pa.title = @"Circle Based Search";

[mapview addAnnotation:pa];
[pa release];

tmC = touchMapCoordinate;
double radius = 1000.0;

self.circleOverlay = [MKCircle circleWithCenterCoordinate:tmC radius:radius];
[mapview removeOverlays:[mapview overlays]];
[mapview addOverlay:circleOverlay];
[mapview removeAnnotations:[mapview annotations]];
}


-(MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id)overlay 
{
if ([overlay isKindOfClass:[MKCircle class]])
{
    MKCircleView* circleView = [[MKCircleView alloc] initWithOverlay:overlay] ;
    circleView.fillColor = [UIColor blueColor];
    circleView.strokeColor = [UIColor blueColor];
    circleView.lineWidth = 5.0;
    circleView.alpha = 0.20;
        return circleView;
}
else
    if ([overlay isKindOfClass:[MKPolygon class]])
{
    MKPolygonView *polygonView = [[MKPolygonView alloc] initWithOverlay:overlay ];
    polygonView.fillColor = [UIColor blueColor];
    polygonView.strokeColor = [UIColor blueColor];
    polygonView.lineWidth = 5.0;
    polygonView.alpha = 0.20;
    return polygonView;
}
return [kml viewForOverlay:overlay];
}

- (void)addCircleWithRadius:(double)radius
{
self.circleOverlay = [MKCircle circleWithCenterCoordinate:tmC radius:radius];
[mapview removeOverlays:[mapview overlays]];
[mapview addOverlay:circleOverlay];
[mapview removeAnnotations:[mapview annotations]];
}

- (IBAction)sliderChanged:(UISlider *)sender
{
    double radius = (sender.value);
[self addCircleWithRadius:radius];
[mapview removeAnnotations:[mapview annotations]];
}
8
задан Hari 6 April 2012 в 13:07
поделиться