Domanda

I have created a custom annotation and a call out for my map view. I need to navigate to another view when the user clicks on call out view or he clicks to the button that added as sub view to the callout view. But both gesture recognizer and add target is not working for me in this case. The setSelected: method was invoked and the view get hidden when tap occurs in call out view.

 @interface VBPunchCardAnnotation : MKAnnotationView{

    UIView *calloutView;
  }

- (id)initWithAnnotation:(id )annotation reuseIdentifier:(NSString *)reuseIdentifier deal:(id)punchdeal
{
  self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier];
  calloutView = [[UIView alloc] init];
  calloutView.hidden = YES;

  infoButton = [UIButton buttonWithType:UIButtonTypeInfoLight];

  [calloutView addSubview:infoButton];

  UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(annotationTapped:)];
  singleTap.numberOfTapsRequired = 1;
  singleTap.delegate = self;
  [calloutView addGestureRecognizer:singleTap];

  [infoButton addTarget:self action:@selector(annotationTapped:) forControlEvents:UIControlEventTouchUpInside];
   [self addSubview:calloutView];

   return self;

}

-(void)setSelected:(BOOL)selected animated:(BOOL)animated
{
 // show/hide callout and swap pin image
  calloutView.hidden = !selected;
  self.image = !selected ? normalPin : selectedPin;
  // dispatch an event to alert app a pin has been selected

  if(selected) [[NSNotificationCenter defaultCenter] postNotificationName:@"punchCardAnnotation" object:self];
}

-(void)annotationTapped:(id)sender{
   [self.delegate punchCardAnnotationClickedForDeal:self.punchDeal];
}
È stato utile?

Soluzione 2

Finally I got the answer. It;s here

Followed this tutorial. Really great solution.

https://github.com/nfarina/calloutview

Happy coding!!

Altri suggerimenti

- (UIView*)hitTest:(CGPoint)point withEvent:(UIEvent*)event
{
    UIView* hitView = [super hitTest:point withEvent:event];
    if ([hitView isKindOfClass:[UIButton class]]) {

    }
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top