如何检测 点击并按住 MKMapView 中的引脚



标题说明了一切。我试图检测MKMapView中针脚上的水龙头,我什至不知道从哪里开始。它不是 UIView,所以我无法添加手势识别器,也无法MKPlaceMark中找到添加它的UIView

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

    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 网站上查看更多详细信息

相关内容

  • 没有找到相关文章

最新更新