我正在将我的应用程序 (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/