2

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];
}
Govind
  • 2,337
  • 33
  • 43

2 Answers2

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

    }
}
Sunny Shah
  • 12,990
  • 9
  • 50
  • 86
  • not entering in to the condition. Also Checked the condition if ([hitView isKindOfClass:[calloutView class]]) ... But this was invoked when the user clicks on the annotation pin. Not when the call out view clicked!! – Govind Feb 24 '14 at 12:46
  • NSLog(@"%@",hitView); – Sunny Shah Feb 24 '14 at 12:55
  • While clicking on the annotation, the call out view is shown and the view name is logged. But while the call out view is clicked, it dismisses perfectly but the Log prints (null) – Govind Feb 24 '14 at 13:00
0

Finally I got the answer. It;s here

Followed this tutorial. Really great solution.

https://github.com/nfarina/calloutview

Happy coding!!

Community
  • 1
  • 1
Govind
  • 2,337
  • 33
  • 43