ios 7 MKMapView 可拖动注释在滚动 map 时更改其位置

标签 ios mkmapview mapkit

我正在将我的应用程序 (MyWorld) 更新到 iOS 7。 该应用程序的一项功能是您可以在 map View 上拖动图钉。 它似乎在 iOS7 中被破坏了。

重现问题的步骤:

  • 向 map 添加注释: - 工作正常
  • 移动注释(拖动)效果很好
  • 滚动 map :问题

每当我滚动时, map View 注释都会随 map 一起移动。它似乎没有附加到正确的 View 或图层??如果未拖动图钉, map View 似乎可以正常工作并且注释保留在定义的位置。 我想知道这是我这边的错误还是已知问题?

我在 github 上创建了一个虚拟 MapViewTest 项目来说明问题:https://github.com/DJMobileInc/MapViewTest

最佳答案

这是来自 MKAnnotationView Class Reference ,对于 MKAnnotationViewDragStateNone 常量:

MKAnnotationViewDragStateNone

The view is not involved in a drag operation. The annotation view is responsible for returning itself to this state when a drag ends or is canceled.

要解决此问题,您的 map View 委托(delegate)需要在注释结束或取消其拖动操作时将注释 View 的 dragState 设置回 MKAnnotationViewDragStateNone。

例如:

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)annotationView
                                 didChangeDragState:(MKAnnotationViewDragState)newState
                                       fromOldState:(MKAnnotationViewDragState)oldState
{
    if (newState == MKAnnotationViewDragStateEnding) {
        // custom code when drag ends...

        // tell the annotation view that the drag is done
        [annotationView setDragState:MKAnnotationViewDragStateNone animated:YES];
    }

    else if (newState == MKAnnotationViewDragStateCanceling) {
        // custom code when drag canceled...

        // tell the annotation view that the drag is done
        [annotationView setDragState:MKAnnotationViewDragStateNone animated:YES];
    }
}

关于ios 7 MKMapView 可拖动注释在滚动 map 时更改其位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18973236/

相关文章:

ios - 如何使 MKMapView 上注释的 Popover 像 Apple 一样随 map 滚动?

iphone - 使 MKMapView 透明但保持覆盖层不透明

ios - 如何在iOS8中使用MKMapView "Shows User Location"?

iphone - 地理围栏指标与位置服务指标

ios - 在 iOS 8.3 上注册 Nib/Class 单元崩溃

ios - 为什么不更新 UIPageControl 上的 currentPage 指示器?

Swift,MKPolyline 如何在坐标点之间创建折线

ios - iOS8上的iBeacon无法正常工作?

ios - iPhone 5, 6, 6 plus ui设计问题

objective-c - UITabBarController w/Multiple MKMapViews