Note that there are some explanatory texts on larger screens.

plurals
  1. POiOS Disable touching through a MKAnnotation
    text
    copied!<p>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 &amp; 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.</p> <p>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.</p> <p>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).</p> <p><strong>Edit 1:</strong> I tried to add a background view with an alpha of 0.1 but it still touches through. My code in the MKAnnotationView:</p> <pre><code>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]; </code></pre> <p>Sadly, this still touches through</p> <p><strong>Edit 2:</strong> 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.</p> <p>I have yet to figure out exactly what part is being touched, but <strong>sometimes</strong> 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.</p> <p>Anyone have any idea why that would happen?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload