0

标题说明了一切。我正在尝试检测 a 中某个引脚上的点击,但MKMapView我什至不知道从哪里开始。它不是 UIView,所以我无法添加手势识别器,也找不到添加它UIView的方法。MKPlaceMark

4

1 回答 1

1

你的问题不是很清楚,但你可以这样做:

    import UIKit
    import MapKit

    protocol HandleMapSearch: class {
        func dropPinZoomIn(placemark:MKPlacemark)
    }

    class ViewController: UIViewController {

       func getDirections(){

           // Here you can put anythings like:

        guard let selectedPin = selectedPin else { return }
        let mapItem = MKMapItem(placemark: selectedPin)
        let launchOptions = [MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving]
        mapItem.openInMapsWithLaunchOptions(launchOptions)
    }
    }

extension ViewController : MKMapViewDelegate {

    func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView?{       

        guard !(annotation is MKUserLocation) else { return nil }
        let reuseId = "pin"
        var pinView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId) as? MKPinAnnotationView
        if pinView == nil {
            pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
        }
        pinView?.pinTintColor = UIColor.orangeColor()    // The pin's color
        pinView?.canShowCallout = true    // To set dialogue bubbles of the pin.

        let smallSquare = CGSize(width: 30, height: 30)
        let button = UIButton(frame: CGRect(origin: CGPointZero, size: smallSquare))       // To initialize the button in the dialogue bubbles of the pin.

        button.addTarget(self, action: #selector(ViewController.getDirections), forControlEvents: .TouchUpInside)    // To set and initialize the button.
        pinView?.leftCalloutAccessoryView = button

        return pinView
    }
}

您可以在Thorn 网站上了解更多详细信息

于 2017-01-16T19:18:37.977 回答