简体   繁体   中英

How to run function when tap MKMapView but return when tap AnnotationView?

In my app, I have an mkmapview with annotations. When I tap annotation some small view with additional informations is appearing.

Now i want to hide this window when i tap the map but no when i tap some annotation.

How to make it?

I think something like this but i dont know how to read it is annotation view tapped. tap gesture:

let mapTap = UITapGestureRecognizer(target: self, action: #selector(mapDidTap(_:)))
    map.addGestureRecognizer(mapTap)

handler:

@objc private func mapDidTap(_ sender: UITapGestureRecognizer) {
    if tapIsOnlyMap {
        hideSmallPopup()
    }
}

You can use var selectedAnnotations: [MKAnnotation] delegate property for detect if any annotation is selected. If there is empty you can hide the window.

One question, how did you open this annotation view when annotation is tapped? I think you can set this 'annotation window' when annotation tapped and then you should not check selectedAnnotations for hide the window.

Enjoy

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM