【问题标题】:Dragged Annotation views do not move with maps拖动的注释视图不随地图移动
【发布时间】:2014-03-26 11:54:56
【问题描述】:

在拖动注释视图后,我的地图出现问题: 当我更改平移地图的区域时,拖动的注释在屏幕中保持固定(其他未拖动的注释正确显示,问题出在每个拖动的注释视图上;请注意,注释视图继续可选择标注和拖动,我能看到的唯一问题是平移地图时它不会移动)

我有什么解决办法吗?这是 ios 7.1 的已知错误吗?还是我的代码中遗漏了什么?

【问题讨论】:

  • 你能贴出你如何添加注释的代码吗?
  • 视频讲解:youtu.be/B49NanaTXL0
  • 使用 addAnnotation 简单地将注解添加到地图中: MyMapAnnotation imagePM = ( MyMapAnnotation *) annotation; MyMapAnnotation *pin = (MyMapAnnotation)[_delegate getAnnotation:self]; pin = [pin初始化]; pin.image = imagePM.image; [pin setCoordinate:imagePM.coordinate]; [pin setTitle:imagePM.title]; [pin setSubtitle:imagePM.subtitle]; pin.identifier = imagePM.identifier; [_mapView addAnnotation:pin];
  • thx,似乎解决了,手动转换到 MKAnnotationViewDragStateNone ;我在答案中发布了 cose 以供将来参考

标签: ios mapkit mkannotationview


【解决方案1】:

似乎代码应该注意进行最后一次转换以重置注释视图,这解决了问题:

-(void)setDragState:(MKAnnotationViewDragState)dragState animated:(BOOL)animated {
    [super setDragState:dragState animated:animated];
    if (dragState==MKAnnotationViewDragStateStarting) {
        [...
    } else if (dragState==MKAnnotationViewDragStateEnding || dragState==MKAnnotationViewDragStateCanceling) {
        ...
        self.dragState = MKAnnotationViewDragStateNone;
    }
}

【讨论】:

    【解决方案2】:

    如果注释被拖动,则必须在其委托方法中将其拖动状态设置为无。这段代码解决了我的问题

        - (void)mapView:(MKMapView *)mapView
         annotationView:(MKAnnotationView *)annotationView
        didChangeDragState:(MKAnnotationViewDragState)newState
           fromOldState:(MKAnnotationViewDragState)oldState
    {
    if (newState == MKAnnotationViewDragStateEnding)
        {
         ..... your code.....
        annotationView.dragState=MKAnnotationViewDragStateNone;
        }
    
    }
    

    【讨论】:

      猜你喜欢
      • 2012-05-30
      • 1970-01-01
      • 1970-01-01
      • 2012-07-11
      • 1970-01-01
      • 2022-12-11
      • 2013-09-26
      • 2020-12-15
      • 1970-01-01
      相关资源
      最近更新 更多