使用UIButton作为子视图的MKannotationView,按钮不响应 [英] MKannotationView with UIButton as subview, button don't respond

查看:151
本文介绍了使用UIButton作为子视图的MKannotationView,按钮不响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我添加了一个带有按钮的视图作为MKAnnotationView的子视图

I have add a view with button as a subview to MKAnnotationView

 CCBigBubleViewController* buble = [[CCBigBubleViewController alloc] init];
 [annotationView addSubView:buble.view];

它显示完美,但按钮不响应点击。

It is shown perfectly, but the button does't respond to tapping.

推荐答案

在MKAnnotationView的实现中,覆盖hitTest方法:

In your implementation of MKAnnotationView, override the hitTest method:

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
    if (CGRectContainsPoint(_button.frame, point)) {
        return _button;
    }
    return [super hitTest:point withEvent:event];
}

您的按钮将接收触摸事件。

Your button will then receive touch events.

这篇关于使用UIButton作为子视图的MKannotationView,按钮不响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆