【发布时间】:2018-10-13 15:45:49
【问题描述】:
在viewDidLoad 中,我将gesturerecognizers 添加到mapView,并将consumeGestureInView 设置为true
在 handleTap 方法中,我将触摸点转换为 latLng,然后用 latLng 设置标记位置,但标记移动很慢很慢
self.mapView.settings.consumesGesturesInView = true
for gestureRecognizer in self.mapView.gestureRecognizers! {
gestureRecognizer.addTarget(self, action: #selector(MapViewController.handleTap(_:)))
}
@objc func handleTap(_ sender: UITapGestureRecognizer) {
var allMarkers = markers
if(sender.numberOfTouches == 1){
var positions = CGPoint()
var newPosition = CLLocationCoordinate2D()
let currentZoom = self.mapView.camera.zoom
switch (sender.state){
case .began:
positions = sender.location(in: self.mapView)
newPosition = self.mapView.projection.coordinate(for: positions)
let ind = self.getNearbymarkers(position: newPosition,markers:allMarkers)
allMarkers[ind].position = newPosition
self.mapView.settings.scrollGestures = false
mapView(self.mapView, didBeginDragging: allMarkers[ind])
self.mapView.settings.scrollGestures = true
break
case .ended:
positions = sender.location(in: self.mapView)
newPosition = self.mapView.projection.coordinate(for: positions)
let ind = self.getNearbymarkers(position: newPosition,markers:allMarkers)
print(ind)
allMarkers[ind].position = newPosition
self.mapView.settings.scrollGestures = false
mapView(self.mapView, didEndDragging: allMarkers[ind])
self.mapView.settings.scrollGestures = true
break
case .changed:
positions = sender.location(in: self.mapView)
newPosition = self.mapView.projection.coordinate(for: positions)
let ind = self.getNearbymarkers(position: newPosition,markers:allMarkers)
print(ind)
allMarkers[ind].position = newPosition
self.mapView.settings.scrollGestures = false
mapView(self.mapView, didDrag: allMarkers[ind])
self.mapView.settings.scrollGestures = true
break
default:
break
}
}
}
问题是当这条线执行然后标记呈现缓慢allMarkers[ind].position = newPosition
就像我的手指快速移动然后标记看起来像在手指后面移动
【问题讨论】:
-
我想像 panGestureRecognizer 那样移动标记
标签: ios swift google-maps google-maps-markers swift4