2
votes

I have a custom MKAnnotation and corresponding MKAnnotationView. When you press on one of the annotations, I open a custom callout bubble which is actually just another MKAnnotation & MKAnnotationView to display a highly customized "callout" (even though it is actually another annotation). This second detailed Annotation takes up a lot of space which is just fine.

What I am trying to accomplish is to disable clicking through this "callout" annotation. It has a few buttons on it that react just fine when pressed but if you miss slightly, you will either close this annotation (presses through the annotation and onto the map which deselects the annotation) or select another annotation behind it.

How can I keep all touches on this particular annotation to stay on this annotation? I want if you touch anywhere on this annotation, only that annotation will receive the touch. If you touch anywhere else, the map will react normally (closing the selected annotation, selecting another annotation, whatever).

Edit 1: I tried to add a background view with an alpha of 0.1 but it still touches through. My code in the MKAnnotationView:

UIView *backgroundView = [[UIView alloc] initWithFrame:self.frame];
[backgroundView setBackgroundColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:0.1]];
[backgroundView setUserInteractionEnabled:YES];

[self addSubview:backgroundView];

Sadly, this still touches through

Edit 2: I managed to slightly fix the issue but with 1 major problem left. Instead of using a UIView as my main view type, I use a UIButton which gives me the same ability to add subviews as I please. Then I set a target to a dummy selector for the whole button (so touching the background triggers the dummy selector). This works great at capturing the touch, with 1 exception.

I have yet to figure out exactly what part is being touched, but sometimes the touch will still go through the button only if there is another annotation behind the button where I touched. This does not happen every time though, only sometimes.

Anyone have any idea why that would happen?

1
Have you found a solution for that? I'm having the exact same problem.Rodrigo Ruiz

1 Answers

0
votes

You can add transparent view at the background of custom callout view to restrict the touches on mapview.