• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

objective-c - annotationView didChangeDragState 被多次触发

[复制链接]
菜鸟教程小白 发表于 2022-12-12 16:38:12 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

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

我的代码目前看起来像:

   - (void)mapViewMKMapView *)mapView  annotationViewMKAnnotationView *)annotationView 
    didChangeDragStateMKAnnotationViewDragState)newState fromOldStateMKAnnotationViewDragState)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。谁能给我任何想法可能导致这种情况?



Best Answer-推荐答案


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

所以代码是:

- (void)mapViewMKMapView *)mapView annotationViewMKAnnotationView *)annotationView didChangeDragStateMKAnnotationViewDragState)newState fromOldStateMKAnnotationViewDragState)oldState
{
  if (newState == MKAnnotationViewDragStateEnding)
  {
    /* ... */
    [annotationView setDragState:MKAnnotationViewDragStateNone];
    // If you are animating - move the above into the completion block
  }
}

关于objective-c - annotationView didChangeDragState 被多次触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6345888/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap