MKOverlay有时会消失

时间:2012-04-05 22:35:46

标签: iphone ios mkmapview mapkit 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]];
}

1 个答案:

答案 0 :(得分:3)

问题解决了。在UIBlider中,在Values下滑块的检查器中检查了属性Continuous,检查了问题。在我取消选中后,问题得到了解决。