ios 7 MKMapView可拖动注释会在滚动地图时更改其位置
我正在将我的应用程序(MyWorld)更新到iOS 7.该应用程序的一个function是您可以在地图视图上拖动图钉。 它似乎在iOS7中被打破了。
重新创建问题的步骤:
- 向地图添加注释: – 工作正常
- 移动注释(拖动)工作正常
- 滚动地图:问题
每当我滚动地图视图时,注释都会随地图一起移动。 它似乎没有附加到右视图或图层? 如果引脚未被拖动,则地图视图似乎工作正常并且注释保持在定义的位置。 我想知道这是我的错误还是已知问题?
我创建了一个虚拟的MapViewTest项目,用于说明github上的问题: https : //github.com/DJMobileInc/MapViewTest
这是来自MKAnnotationView类参考 ,用于MKAnnotationViewDragStateNone常量:
MKAnnotationViewDragStateNone
视图不参与拖动操作。 拖动结束或取消时,注释视图负责将自身返回到此状态。
要解决此问题,地图视图委托将需要在注释结束或取消其拖动操作时将注释视图的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]; } }
我有同样的问题,我解决了它将“setDragState”添加到我的MKAnnotationView类。
这是一个旧的解决方案,但它对我有用(iOS7): https ://stackoverflow.com/a/4457772/2410800