跳过选择,直接在 MapKit 标记中拖动
Skipping Selection, and Going Directly to Dragging in MapKit Marker
更新:我真的问错了问题。
第一次点击选择标记。我想做的是跳过选择阶段,立即开始拖动。选择打断了长按事件,我只想让长按事件开始选择。
我尝试使用 "starting" 作为状态调用 setDragState,但这不起作用。该对象忘记了它处于拖动状态,您仍然需要第二次点击。
原版:
这个问题我已经有一段时间了。我在 MKMapView 对象中有一个可拖动的标记。
但是,在我可以拖动它之前,第一次总是需要在标记上触摸两 (2) 次。一旦完成一次,在随后的拖动中,第一次触摸会立即启动拖动。只是第一次拖动需要第二次触摸。
这不是世界末日,但有点烦人。
关于如何使第一次触摸也成为拖动触摸有什么想法吗?
好的。我想出了如何做到这一点。
我 "pre-select" 标记。这意味着我不能为它做一个简单的标注,这对我来说没什么大不了的,但它给了我我想要的。
更新:代码或它没有发生。
我添加了几个 MKMapViewDelegate 函数:
/* ################################################################## */
/**
This responds to the map's region being changed.
We simply use this to "preselect" the marker, so there's no need for two taps.
- parameter mapView: The MKMapView object that contains the marker being moved.
- parameter animated: True, if the change was animated.
*/
func mapView(_ mapView: MKMapView, regionDidChangeAnimated animated: Bool) {
self.mapView.selectAnnotation(self._meetingMarker, animated: false)
}
/* ################################################################## */
/**
This responds to the marker's selection turning off.
We simply use this to "preselect" the marker, so there's no need for two taps.
- parameter mapView: The MKMapView object that contains the marker being moved.
- parameter didDeselect: The annotation view (it's ignored. We always select our marker).
*/
func mapView(_ mapView: MKMapView, didDeselect view: MKAnnotationView) {
self.mapView.selectAnnotation(self._meetingMarker, animated: false)
}
第一个在我设置地图时调用,第二个在试图关闭选择时调用。
注意:这仅适用于具有单个标记的地图。
更新:我真的问错了问题。 第一次点击选择标记。我想做的是跳过选择阶段,立即开始拖动。选择打断了长按事件,我只想让长按事件开始选择。 我尝试使用 "starting" 作为状态调用 setDragState,但这不起作用。该对象忘记了它处于拖动状态,您仍然需要第二次点击。
原版:
这个问题我已经有一段时间了。我在 MKMapView 对象中有一个可拖动的标记。
但是,在我可以拖动它之前,第一次总是需要在标记上触摸两 (2) 次。一旦完成一次,在随后的拖动中,第一次触摸会立即启动拖动。只是第一次拖动需要第二次触摸。
这不是世界末日,但有点烦人。
关于如何使第一次触摸也成为拖动触摸有什么想法吗?
好的。我想出了如何做到这一点。
我 "pre-select" 标记。这意味着我不能为它做一个简单的标注,这对我来说没什么大不了的,但它给了我我想要的。
更新:代码或它没有发生。
我添加了几个 MKMapViewDelegate 函数:
/* ################################################################## */
/**
This responds to the map's region being changed.
We simply use this to "preselect" the marker, so there's no need for two taps.
- parameter mapView: The MKMapView object that contains the marker being moved.
- parameter animated: True, if the change was animated.
*/
func mapView(_ mapView: MKMapView, regionDidChangeAnimated animated: Bool) {
self.mapView.selectAnnotation(self._meetingMarker, animated: false)
}
/* ################################################################## */
/**
This responds to the marker's selection turning off.
We simply use this to "preselect" the marker, so there's no need for two taps.
- parameter mapView: The MKMapView object that contains the marker being moved.
- parameter didDeselect: The annotation view (it's ignored. We always select our marker).
*/
func mapView(_ mapView: MKMapView, didDeselect view: MKAnnotationView) {
self.mapView.selectAnnotation(self._meetingMarker, animated: false)
}
第一个在我设置地图时调用,第二个在试图关闭选择时调用。
注意:这仅适用于具有单个标记的地图。