8
我在我的映射表疊加選項:一個MKCircleOverlay和MKPolygonOverlay.The第一是可變半徑,通過UISlider.The最後控制是根據定製我非常改變corners.If的數量和位置快速的圓的半徑(減少UISlider的值),有時我覆蓋消失(圓圈),之後的多邊形不能再被繪製(當然圓太)。沒有崩潰的app.What的會是什麼?MKOverlay有時消失
下面是一些代碼,我用:
- (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]];
}
請告訴我們您所使用的調整圈子中的代碼。直到我們看到我們只能猜測可能發生的事情。 – sosborn 2012-04-06 05:15:20
剛剛完成,對不起,我完全忘了添加代碼。 – Hari 2012-04-06 13:08:42
你應該NSLog半徑在你的sliderChanged看看它是否正在返回你所期望的。同時記錄tmc值以確保中心保持在您期望的位置。不確定代碼結構,但是當您緩慢移動滑塊時,您可能正在激活長觸摸識別器。 – sosborn 2012-04-06 13:43:10