自定义MQAnnotationViewbutton不可点击
我正在使用MapQuest,但我认为这不是问题。
我有Map(MapQuest)和自定义引脚。 我可以点击引脚和我的自定义标注(标签和一个button的xib文件)popup,一切工作正常。 唯一的问题是,我不能按自定义标注视图(UIView)上的button。
这是我的代码:
-(MQAnnotationView*)mapView:(MQMapView *)aMapView viewForAnnotation:(id<MQAnnotation>)annotation { static NSString* identifier = @"Pins"; MQAnnotationView * annotationView = (MQAnnotationView *)[self->mapView dequeueReusableAnnotationViewWithIdentifier:identifier]; annotationView = [[MQAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier]; annotationView.image = [UIImage imageNamed:@"marker_schuhe"]; annotationView.enabled = YES; annotationView.canShowCallout = NO; return annotationView; }
在我的didSelectAnnotationView方法中:
- (void)mapView:(MQMapView *)mapView didSelectAnnotationView:(MQAnnotationView *)view { callOutView *calloutView = (callOutView *)[[[NSBundle mainBundle] loadNibNamed:@"callOutView" owner:self options:nil] objectAtIndex:0]; CGRect calloutViewFrame = calloutView.frame; calloutViewFrame.origin = CGPointMake(-calloutViewFrame.size.width/2 + 15, -calloutViewFrame.size.height); calloutView.frame = calloutViewFrame; [calloutView.my_button addTarget:self action:@selector(button_pressed:) forControlEvents:UIControlEventTouchUpInside]; //here is something wrong, button_pressed is never called [view addSubview:calloutView]; }
设置userInteractionEnabled = YES;
在calloutView?
– 用户评论后编辑
如果@select器不工作(因为MKAnotationView拦截它)尝试添加一个UIGesture
到你的UIButton
像这样:
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(button_pressed:)]; tap.numberOfTapsRequired = 1; [calloutView.my_button addGestureRecognizer:tap];