title: How to perform action when user taps on map using MapKit, Swift
body: <p>I have custom views, that appear when user taps on annotation, but I don't know how to make those views disappear when user taps somewhere else on map.
  In Google Map SDK for iOS it would be <code>didTapAtCoordinate</code> and then I would set <code>view.hidden = true</code>.</p>
  
  <p>I think it can be done using <code>touchBegan</code>, although I haven't used this function before? Although I would prefer MapKit version of Googles <code>didTapAtCoordinate</code>.</p>
  
  <p><strong>EDIT</strong></p>
  
  <pre><code>class ViewController: UIViewController, MKMapViewDelegate {
  
      @IBOutlet weak var mapView: MKMapView!
      @IBOutlet weak var myCustomView: UIView!
  
      override func viewDidLoad() {
          super.viewDidLoad()
  
          myCustomView.hidden = true
          //MyAnnatationClass is my class where I store MKAnnatations with additional details
          let ann = MyAnnatationClass(coordinate: CLLocationCoordinate2D(latitude: 54.694084, longitude: 25.288782), title: "DEMO2", name: "Some Name")
          mapView.addAnnotation(ann)
     }
  
     func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -&gt; MKAnnotationView? {
  
          let identifier = "id"
  
          if annotation.isKindOfClass(MyAnnatationClass.self) {
  
              var annotationView = mapView.dequeueReusableAnnotationViewWithIdentifier(identifier)
  
              if annotationView == nil {
  
                  annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: identifier)
                  annotationView?.image = UIImage(named: "pin.png")
                  annotationView!.canShowCallout = true
              } else {
  
                  annotationView!.annotation = annotation
              }
  
              return annotationView
          }
  
          return nil
      }
  
      func mapView(mapView: MKMapView, didSelectAnnotationView view: MKAnnotationView) {
          //Set view details
          let myAnn = view.annotation as! MyAnnatationClass
          someViewLabel.text = myAnn.name
          myCustomView.hidden = false
  
          let annotationTap = UITapGestureRecognizer(target: self, action: "tapRecognized:")
          annotationTap.numberOfTapsRequired = 1
          view.addGestureRecognizer(annotationTap)
  
          let selectedAnnotations = mapView.selectedAnnotations
  
          for annotationView in selectedAnnotations{
              mapView.deselectAnnotation(annotationView, animated: true)
          }
      }
  
      func mapView(mapView: MKMapView, didDeselectAnnotationView view: MKAnnotationView) {
          view.hidden = true 
      }
  
      func tapRecognized(gesture:UITapGestureRecognizer){
  
          let selectedAnnotations = mapView.selectedAnnotations
  
          for annotationView in selectedAnnotations{
              mapView.deselectAnnotation(annotationView, animated: true)
          }
      }
  }
  </code></pre>
  
  <p>Currently, when I touch annotation, <code>myCustomView</code> appears and annotation disappears. If in <code>didDeselectAnnotationView</code> I change <code>view</code> to <code>myCustomView</code> then custom view never appears.</p>