自定义MQAnnotationView按钮不可单击 [英] Custom MQAnnotationView button is not clickable
问题描述
我正在使用MapQuest,但我认为这不是问题.
I'm working with MapQuest but I think that is not the problem.
我有地图(带有MapQuest)和自定义图钉.我可以点击图钉,然后弹出我的自定义标注(带有标签和一个按钮的Xib文件),一切正常.唯一的问题是我无法按自定义标注视图(UIView)上的按钮.
I have map (with MapQuest) and custom pins on it. I can tap the pins and my custom callout (xib-file with labels and one button) pops up and everything is working fine. The only problem is that I can't press the button on the custom callout view (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方法中:
And in my didSelectAnnotationView method:
- (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];
}
推荐答案
在calloutView上设置userInteractionEnabled = YES;
?
Set userInteractionEnabled = YES;
on the calloutView?
-在用户评论后编辑
如果@selector
不起作用(因为MKAnotationView拦截了它),请尝试将UIGesture
添加到您的UIButton
中,如下所示:
If @selector
isn't working (because the MKAnotationView intercepts it) try adding a UIGesture
to your UIButton
like this:
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]
initWithTarget:self action:@selector(button_pressed:)];
tap.numberOfTapsRequired = 1;
[calloutView.my_button addGestureRecognizer:tap];
这篇关于自定义MQAnnotationView按钮不可单击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!