Prevent touch spread to annotation below

I have a custom one MKAnnotationView. In my method, setselected:animatedI add a custom bubble loaded from the tip to it, adjust the annotation view frame to include this view, and redraw the annotation circle in a different color, for example (the first is not selected, the second is selected, blue is the frame, green is the user view bubble with alpha = 0.8, red - abstract):

enter image description here

It works fine, the bubble appears and can only be "closed" by clicking on it (so I enlarged the frame). I have buttons on this bubble and they are available for clicks if there is nothing under the annotation only on the map.

BUT, when there is another annotation under the stem bubble, I can click through the entire bubble. When I press one of the buttons, a red highlight appears, but the other annotation is selected because it didSelectAnnotationViewworks ...

I tried to make the bubble opaque / translucent, no luck; set exclusiveTouch on buttons, in the view itself, no luck; I tried not to get confused with the frame, you can still click. Am I missing something?

thank

Change : . In short. Why can I go through UIViewthat added to addSubviewin MKAnnotationView if there is another MKAnnotaionView in this UIView?

Details:

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
  if(selected)
  {
    initialFrame = self.frame;       // save frame and offset to restore when deselected
    initialOffset = self.centerOffset;  // frame is correct for a circle, like {{2.35, 1.47}, {12, 12}}

    if (!self.customCallout) 
    {
      self.customCallout = [[[NSBundle mainBundle] loadNibNamed:@"CustomCallout" owner:self options:nil] objectAtIndex:0];
    }
    // adjust annotationview frame and center
    // callout is 200x120, here frame is {{2.35, 1.47}, {200, 132}} 
    self.customCallout.layer.cornerRadius=5;
    self.customCallout.exclusiveTouch = YES;
    [self addSubview:self.customCallout];
  }
...
}

initWithAnnotation has the following meanings:

   self.canShowCallout = NO;  // to appear the subview
   self.exclusiveTouch = YES; // ...
   self.enabled = YES;
   self.opaque = YES;
+3
source share
3 answers

touch touch (touchBegan: touchesEnded: ..) documentation:

. UIKit UIResponder, UIView, .

MKAnnotationView UIVIew. , , , .

, annotationView .

+3

,

1, the button on bubble
2, didSelectAnnotationView

,

touchesBegan:touches
touchesMove:touches
touchesEnd:touches

0

I think you will find the following links very useful:

http://blog.asynchrony.com/2010/09/building-custom-map-annotation-callouts-part-2/

How to make MKAnnotationView touchscreen?

The first link discusses (among other things) how to prevent the spread, and the second - how to detect touch.

0
source

All Articles