gpt4 book ai didi

iphone - MKOverlay 有时会消失

转载 作者:可可西里 更新时间:2023-11-01 03:17:56 27 4
gpt4 key购买 nike

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

最佳答案

问题已解决。这是 UISlider 的问题,在 Nib 中,在 Values 下的 slider 检查器中检查了属性 Continuous。在我取消选中之后,问题已解决。

关于iphone - MKOverlay 有时会消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10036967/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com