Home > Net >  Adding Layer Mask to MKAnnotationView, makes its title window never show
Adding Layer Mask to MKAnnotationView, makes its title window never show

Time:10-15

As the title says after I use :

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

...

let shapeLayer = CAShapeLayer()
shapeLayer.path = UIBezierPath(ovalIn: rect).cgPath
shapeLayer.backgroundColor = backgroundColor?.cgColor

mkAnnotationView?.layer.mask = shapeLayer //<- window showing title stops working

window showing title

The custom view showing the title (check image in question) that should appear when I press the annotation view in the map, never shows.

I don't see how those lines of code can affect this feature...

Can someone help me?

CodePudding user response:

I don't see how those lines of code can affect this feature...

You don't? Well, a mask means "don't show anything outside me" (where "me" is the parts of the mask that are opaque). The title view you're showing in your screen shot is outside that mask, so it cannot show. It's coming into existence, all right, and it's trying to appear (as you can prove to yourself by looking at the situation in the View Debugger); but it can't, because you masked it out.

  • Related