2017-02-21 25 views
0

已更新:我真的問錯了問題。 第一個水龍頭選擇標記。我想要做的是跳過選擇階段,並立即開始拖動。選擇會中斷長按事件,我只想要長按事件來開始選擇。 我試着用「開始」作爲狀態來調用setDragState,但那不起作用。該對象忘記它處於拖動狀態,而您仍需要第二次敲擊。跳過選擇,並直接拖動MapKit標記

ORIGINAL:

這是一個問題,我已經有一段時間。我在MKMapView對象中有一個可拖動的標記。

但是,在我拖動它之前,它總是首先在標記上進行兩(2)次觸摸。一旦完成一次,在隨後的拖動中,第一次觸摸立即啓動拖動。這只是第一次拖動需要第二次觸摸。

這不是世界末日,但它有點煩人。

有關如何使第一次觸摸也成爲拖動觸摸的任何想法?

回答

0

好的。我想出瞭如何做到這一點。

我「預先選擇」標記。這意味着我不能爲它做一個簡單的標註,在我的情況下沒有什麼大不了的,但它給了我想要的東西。

更新:代碼或它沒有發生。

我增加了幾個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) 
} 

當我設置了地圖,每當一些試圖關閉選擇第二個叫首先是所謂的。

注意:這僅適用於帶有單個標記的地圖。