Adding subview to MKMapView that's above the map but below the annotation views?

前端 未结 3 1155
感动是毒
感动是毒 2021-02-07 06:16

For an app I\'m building, I have a custom \"old map\" effect PNG that I\'d like to overlay on the MKMapView view. Unfortunately, neither way I\'ve tried to do this is exactly ri

3条回答
  •  情深已故
    2021-02-07 06:28

    It's pretty old, but maybe still relevant for some of you.

    I wanted to make the map darker, but not the annotation views.

    What i did was very simple and i don't yet know if it has some fallbacks...

    I put a UIView with a black-transparent background above the MKMapView, and then added the following code:

    - (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views
    {
        for (MKAnnotationView *view in views) {
            view.center = [self.mapView convertCoordinate:view.annotation.coordinate toPointToView:self.viewDark];
            [self.viewDark addSubview:view];
        }
    }
    

    Hope it helps.. and of course - if you find any issues about this solution please let me know :)

    Edit #1: Forgot to mention that self.viewDark should have userInteraction disabled.

    Edit #2: Another thing that helped me is setting self.viewDark's autoresizesSubviews to NO.

提交回复
热议问题