0

我是 iOS 新手。我使用了这个答案中的代码:https ://stackoverflow.com/a/3999583/1572234

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)annotationView 
didChangeDragState:(MKAnnotationViewDragState)newState 
fromOldState:(MKAnnotationViewDragState)oldState 
{
if (newState == MKAnnotationViewDragStateEnding)
   {
    NSLog(@"didChangeDragState");
   }
}

- (void) mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)annotationView
{
if ([[annotationView.annotation title] isEqualToString:@"2nd"]||[[annotationView.annotation title] isEqualToString:@"3rd"])
   {
    NSLog(@"didSelectAnnotationView");
   }
}

但是在我尝试拖动 pin 三次之后,我在调试区域看到了这个:

 2012-08-05 14:47:06.962 TestApp[1692:11603] didSelectAnnotationView
 2012-08-05 14:47:11.825 TestApp[1692:11603] didChangeDragState
 2012-08-05 14:47:16.269 TestApp[1692:11603] didSelectAnnotationView
 2012-08-05 14:47:20.205 TestApp[1692:11603] didChangeDragState
 2012-08-05 14:47:20.207 TestApp[1692:11603] didChangeDragState
 2012-08-05 14:47:24.033 TestApp[1692:11603] didSelectAnnotationView
 2012-08-05 14:47:26.811 TestApp[1692:11603] didChangeDragState
 2012-08-05 14:47:26.814 TestApp[1692:11603] didChangeDragState
 2012-08-05 14:47:26.816 TestApp[1692:11603] didChangeDragState

我只需要一次调用 NSLog(@"didChangeDragState"),每次我拖动 pin 时,我错过了什么?帮助请。

4

1 回答 1

1

这是ios中的一个老错误。一年多前我向苹果报告了这一点,但他们说他们无法重现它......我添加了自己的修复:

 if (newState == MKAnnotationViewDragStateEnding)
{
    CLLocationCoordinate2D droppedAt = annotationView.annotation.coordinate;
    //drmap1 and drmap2 initialized to 0 before

    double d1=drmap1-droppedAt.latitude;
    double d2=drmap2-droppedAt.longitude;
    if(d1<0.000001&&d1>=-0.000001&&d2<0.000001&&d2>=-0.000001) return; //V1.2a fix a bug in ios

    drmap1=droppedAt.latitude;
    drmap2=droppedAt.longitude;
于 2012-09-04T09:17:09.317 回答