我正在使用MapQuest,但我认为这不是问题。
我有地图(使用MapQuest)和自定义引脚。我可以点击引脚和我的自定义标注(带标签和一个按钮的xib文件)弹出,一切正常。唯一的问题是我无法按下自定义标注视图(UIView)上的按钮。
这是我的代码:
-(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];
}
答案 0 :(得分:0)
在calloutView上设置userInteractionEnabled = YES;
?
- 在用户评论后编辑
如果@selector
无效(因为MKAnotationView拦截它),请尝试向UIGesture
添加UIButton
,如下所示:
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]
initWithTarget:self action:@selector(button_pressed:)];
tap.numberOfTapsRequired = 1;
[calloutView.my_button addGestureRecognizer:tap];