如何通过点击更改地图注释位置仍然能够平移? (包括gif)

时间:2016-11-13 10:39:56

标签: ios swift mapkit

我已经能够添加注释并更改它的位置,但是如何通过点击更改它的位置,同时仍然可以在地图中平移? (请看一下这个gif,它显示了需要的内容)。

swift map

1 个答案:

答案 0 :(得分:0)

解决了,希望有些人觉得它很有用

var map1 = MKMapView()
var pointAnnotation:MKPointAnnotation = MKPointAnnotation()

func handleTap(gestureReconizer: UITapGestureRecognizer)
{
    let location = gestureReconizer.locationInView(map1)
    let coordinate = map1.convertPoint(location,toCoordinateFromView: map1)
    pointAnnotation.coordinate = coordinate
}

override func viewDidAppear(animated: Bool)
{
    map1 = self.scrollView.viewWithTag(801) as! MKMapView
    map1.showsUserLocation = true
    map1.tintColor = UIColor.blueColor()

    let initialLocation = CLLocation(latitude: ram.currentLat, longitude: ram.currentLon )
    self.centerMapOnLocation(initialLocation, map: map1, regionRadius: 707)
    var coordinates : CLLocationCoordinate2D = CLLocationCoordinate2D(latitude: ram.currentLat, longitude: ram.currentLon)
    pointAnnotation.coordinate = coordinates

    map1.addAnnotation(pointAnnotation)

    let gestureRecognizer = UITapGestureRecognizer(target: self, action:"handleTap:")
    gestureRecognizer.delegate = self
    map1.addGestureRecognizer(gestureRecognizer)
}