【问题标题】:MKOverlay sometimes disappearsMKOverlay 有时会消失
【发布时间】:2012-04-05 22:35:45
【问题描述】:

我的地图中有两个覆盖选项:一个 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]];
}

【问题讨论】:

  • 请向我们展示您用于调整圆圈大小的代码。直到我们看到我们只能猜测可能发生的事情。
  • 刚刚完成,抱歉,我完全忘记添加代码了。
  • 你应该 NSLog 你的 sliderChanged 中的半径,看看它是否返回了你所期望的。还要记录 tmc 值以确保中心位于您期望的位置。不确定代码结构,但是当您缓慢移动滑块时,您可能会激活长触摸识别器。
  • 实际上我看到它的功能,尽管没有 NSlogs,但圆圈的大小正在改变,并且中心明显在那里,它没有改变。
  • 但是半径是你所期望的吗?

标签: iphone ios mkmapview mapkit mkoverlay


【解决方案1】:

问题已解决。这是 UISlider 的问题,在笔尖中,在 Values 下的滑块检查器中,检查了属性 Continuous。在我取消选中后,问题解决了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-31
    • 2021-02-22
    • 2018-05-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多