2012-04-05 3 views
8

지도에 두 가지 오버레이 옵션 인 MKCircleOverlay와 MKPolygonOverlay가 있습니다. 첫 번째는 가변 반경이며 UISlider를 통해 제어됩니다. 마지막 점은 모서리의 수와 위치에 따라 맞춤 설정할 수 있습니다. 빨리 원의 반지름을 줄이면 (UISlider의 값을 줄임) 때로는 오버레이가 사라지고 (원) 폴리곤을 더 이상 그릴 수 없습니다 (물론 원). 앱이 충돌하지 않습니다. 무엇일까요? ,때때로 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]]; 
} 
+0

서클의 크기를 조정하는 데 사용하는 코드를 표시하십시오. 우리가 볼 때까지 우리는 일어날 수있는 일에 대해서만 짐작할 수 있습니다. – sosborn

+0

방금 ​​끝났습니다. 죄송합니다. 코드를 추가하는 것을 완전히 잊었습니다. – Hari

+0

sliderChanged에 반지름을 NSLog로 설정하여 기대 한 값을 반환하는지 확인해야합니다. 또한 tmc 값을 기록하여 센터가 머무를 것으로 예상되는 위치에 있는지 확인하십시오. 코드 구조가 확실하지 않지만 슬라이더를 천천히 움직이면 긴 터치 인식기가 활성화 될 수 있습니다. – sosborn

답변

3

문제 solved.It이 Values에서 슬라이더의 속성에서, 펜촉에, Continuous이었다 재산 UISlider 뭔가했다 checked.After 나는 그것을 취소 : 여기

내가 사용하는 몇 가지 코드 문제가 해결되었습니다.

관련 문제