CommentsView didChangeDragState 被多次触发

发布于 2024-11-15 04:11:33 字数 2784 浏览 2 评论 0原文

我在 IOS4 Mapkit 中有一个可拖动注释,并且当注释被拖动到新位置时我试图调用一个事件。

我的代码当前如下所示:

   - (void)mapView:(MKMapView *)mapView  annotationView:(MKAnnotationView *)annotationView 
    didChangeDragState:(MKAnnotationViewDragState)newState fromOldState:(MKAnnotationViewDragState)oldState 
{
    if (newState == MKAnnotationViewDragStateEnding)
    {
        CLLocationCoordinate2D droppedAt = annotationView.annotation.coordinate;
        NSLog(@"dropped at %f,%f", droppedAt.latitude, droppedAt.longitude);

        //update the annotation
        //see if its an information annotation
        if ([annotationView.annotation isKindOfClass:[InfoAnnotation class]]) {
            NSLog(@"Info annotation updating..");
            InfoAnnotation* userAnnotation = ((InfoAnnotation *)annotationView.annotation);
            [userAnnotation updateLocationWithServerForConvoy: self.title];
        }

    }
}

代码只是记录更新,然后告诉注释将其更新发送到我的服务器,这是一个自定义方法。

这个方法似乎被多次触发,请参阅此处的日志:

2011-06-15 01:12:39.347 Convoy[1699:207] dropped at 37.340206,-122.027550
2011-06-15 01:12:39.347 Convoy[1699:207] Info annotation updating..
2011-06-15 01:12:39.658 Convoy[1699:207] dropped at 37.340206,-122.027550
2011-06-15 01:12:39.659 Convoy[1699:207] Info annotation updating..
2011-06-15 01:12:39.957 Convoy[1699:207] dropped at 37.340206,-122.027550
2011-06-15 01:12:39.958 Convoy[1699:207] Info annotation updating..


2011-06-15 01:12:43.415 Convoy[1699:207] dropped at 37.339251,-122.026691
2011-06-15 01:12:43.416 Convoy[1699:207] Info annotation updating..
2011-06-15 01:12:43.713 Convoy[1699:207] dropped at 37.339251,-122.026691
2011-06-15 01:12:43.713 Convoy[1699:207] Info annotation updating..
2011-06-15 01:12:44.006 Convoy[1699:207] dropped at 37.339251,-122.026691
2011-06-15 01:12:44.006 Convoy[1699:207] Info annotation updating..
2011-06-15 01:12:44.297 Convoy[1699:207] dropped at 37.339251,-122.026691
2011-06-15 01:12:44.297 Convoy[1699:207] Info annotation updating..


2011-06-15 01:12:54.825 Convoy[1699:207] dropped at 37.337135,-122.025833
2011-06-15 01:12:54.825 Convoy[1699:207] Info annotation updating..
2011-06-15 01:12:55.150 Convoy[1699:207] dropped at 37.337135,-122.025833
2011-06-15 01:12:55.150 Convoy[1699:207] Info annotation updating..
2011-06-15 01:12:55.475 Convoy[1699:207] dropped at 37.337135,-122.025833
2011-06-15 01:12:55.476 Convoy[1699:207] Info annotation updating..
2011-06-15 01:12:55.771 Convoy[1699:207] dropped at 37.337135,-122.025833
2011-06-15 01:12:55.772 Convoy[1699:207] Info annotation updating..
2011-06-15 01:12:56.070 Convoy[1699:207] dropped at 37.337135,-122.025833
2011-06-15 01:12:56.070 Convoy[1699:207] Info annotation updating..

每次我拖动它(即在间隙中)时,它的调用次数似乎都会增加 1。谁能告诉我可能是什么原因造成的?

I've got a draggable annotation in IOS4 mapkit, and I'm trying to call an event when the annotation is dragged to a new position.

my code currently looks like:

   - (void)mapView:(MKMapView *)mapView  annotationView:(MKAnnotationView *)annotationView 
    didChangeDragState:(MKAnnotationViewDragState)newState fromOldState:(MKAnnotationViewDragState)oldState 
{
    if (newState == MKAnnotationViewDragStateEnding)
    {
        CLLocationCoordinate2D droppedAt = annotationView.annotation.coordinate;
        NSLog(@"dropped at %f,%f", droppedAt.latitude, droppedAt.longitude);

        //update the annotation
        //see if its an information annotation
        if ([annotationView.annotation isKindOfClass:[InfoAnnotation class]]) {
            NSLog(@"Info annotation updating..");
            InfoAnnotation* userAnnotation = ((InfoAnnotation *)annotationView.annotation);
            [userAnnotation updateLocationWithServerForConvoy: self.title];
        }

    }
}

the code simply logs the update and then tells the annotation to send its update to my server, which is a custom method.

This method seems to be getting fired multiple times, see the log here:

2011-06-15 01:12:39.347 Convoy[1699:207] dropped at 37.340206,-122.027550
2011-06-15 01:12:39.347 Convoy[1699:207] Info annotation updating..
2011-06-15 01:12:39.658 Convoy[1699:207] dropped at 37.340206,-122.027550
2011-06-15 01:12:39.659 Convoy[1699:207] Info annotation updating..
2011-06-15 01:12:39.957 Convoy[1699:207] dropped at 37.340206,-122.027550
2011-06-15 01:12:39.958 Convoy[1699:207] Info annotation updating..


2011-06-15 01:12:43.415 Convoy[1699:207] dropped at 37.339251,-122.026691
2011-06-15 01:12:43.416 Convoy[1699:207] Info annotation updating..
2011-06-15 01:12:43.713 Convoy[1699:207] dropped at 37.339251,-122.026691
2011-06-15 01:12:43.713 Convoy[1699:207] Info annotation updating..
2011-06-15 01:12:44.006 Convoy[1699:207] dropped at 37.339251,-122.026691
2011-06-15 01:12:44.006 Convoy[1699:207] Info annotation updating..
2011-06-15 01:12:44.297 Convoy[1699:207] dropped at 37.339251,-122.026691
2011-06-15 01:12:44.297 Convoy[1699:207] Info annotation updating..


2011-06-15 01:12:54.825 Convoy[1699:207] dropped at 37.337135,-122.025833
2011-06-15 01:12:54.825 Convoy[1699:207] Info annotation updating..
2011-06-15 01:12:55.150 Convoy[1699:207] dropped at 37.337135,-122.025833
2011-06-15 01:12:55.150 Convoy[1699:207] Info annotation updating..
2011-06-15 01:12:55.475 Convoy[1699:207] dropped at 37.337135,-122.025833
2011-06-15 01:12:55.476 Convoy[1699:207] Info annotation updating..
2011-06-15 01:12:55.771 Convoy[1699:207] dropped at 37.337135,-122.025833
2011-06-15 01:12:55.772 Convoy[1699:207] Info annotation updating..
2011-06-15 01:12:56.070 Convoy[1699:207] dropped at 37.337135,-122.025833
2011-06-15 01:12:56.070 Convoy[1699:207] Info annotation updating..

Each time I drag it (ie in the gaps) it seems to add 1 to the amount of times it's called. Can anyone give me any idea what may be causing this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

喜爱纠缠 2024-11-22 04:11:33

如果有人仍然想知道 - 你必须将 MKAnnotationView 拖动状态设置为
MKAnnotationViewDragStateNone

所以代码是:

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)annotationView didChangeDragState:(MKAnnotationViewDragState)newState fromOldState:(MKAnnotationViewDragState)oldState
{
  if (newState == MKAnnotationViewDragStateEnding)
  {
    /* ... */
    [annotationView setDragState:MKAnnotationViewDragStateNone];
    // If you are animating - move the above into the completion block
  }
}

If anyone is still wondering - you have to set the MKAnnotationView drag state to
MKAnnotationViewDragStateNone.

So the code would be:

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)annotationView didChangeDragState:(MKAnnotationViewDragState)newState fromOldState:(MKAnnotationViewDragState)oldState
{
  if (newState == MKAnnotationViewDragStateEnding)
  {
    /* ... */
    [annotationView setDragState:MKAnnotationViewDragStateNone];
    // If you are animating - move the above into the completion block
  }
}
仙气飘飘 2024-11-22 04:11:33

这确实看起来很奇怪。您是否考虑过简单地连接到注释的 setCooperative 方法?每当通过拖动移动 MKMapAnnotation 时,MapKit 都会调用此函数一次。

That does seem odd. Have you thought about simply hooking in to your annotation's setCoordinate method instead? MapKit calls this once whenever an MKMapAnnotation is moved by dragging.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文