ios 7 MKMapView可拖动注释会在滚动地图时更改其位置 [英] ios 7 MKMapView draggable annotation change it's position when map is scrolled
问题描述
我正在将我的应用程序(MyWorld)更新为iOS 7.
该应用程序的一个功能是您可以在地图视图上拖动图钉。
在iOS7中好像坏了。
I am updating my app (MyWorld) to iOS 7. One of the features of the app is that you can drag pin on the map view. It seems to be broken in iOS7.
重新创建问题的步骤:
- 向地图添加注释: - 工作正常
- 移动注释(拖动)正常工作
- 滚动地图:问题
- Adding Annotation to the map: - works fine
- Moving Annotation (Dragging) works fine
- Scrolling the map: Problem
每当我滚动地图视图注释时与地图一起移动。它似乎没有附加到右视图或图层?如果引脚未被拖动,则地图视图似乎工作正常并且注释保持在定义的位置。
我想知道这是我的错误还是已知的问题?
Whenever I scroll the map view annotation is moved with the map. It seems like it's not attached to the right view or layer?? If the pin is not dragged map view seems to work fine and annotation stays in defined position. I wonder if this is a mistake on my side or a known issue?
我创建了一个虚拟的MapViewTest项目来解决github上的问题: https://github.com/DJMobileInc/MapViewTest
I created a dummy MapViewTest project that ilusstrates the problem on github: https://github.com/DJMobileInc/MapViewTest
推荐答案
这是来自 MKAnnotationView类参考,用于MKAnnotationViewDragStateNone常量:
This is from the MKAnnotationView Class Reference, for the MKAnnotationViewDragStateNone constant:
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.
要解决此问题,请修改地图视图当注释结束或取消其拖动操作时,委托将需要将注释视图的dragState设置回MKAnnotationViewDragStateNone。
To fix the problem, your map view delegate will need to set the annotation view's dragState back to MKAnnotationViewDragStateNone when ever the annotation ends or cancels its drag operation.
例如:
- (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可拖动注释会在滚动地图时更改其位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!