ios - 标注注释 View 不可点击中心

标签 ios objective-c mkmapview mkannotationview

我希望我的所有 View 都是可点击的,而不仅仅是 leftCalloutAccessoryView或 r ightCalloutAccessoryView ,我也希望中心也可以点击

enter image description here

最佳答案

您可以使用,

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [touches anyObject];

    CGPoint touchPoint = [touch locationInView:calloutView];

        BOOL isPointInsideView = [calloutView pointInside:touchPoint withEvent:nil];
        if (isPointInsideView)
        {
           // place your action code.  
        }

}

或者你可以使用,
    UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapCalloutAction:)];
    tapGestureRecognizer.delegate = self;
    tapGestureRecognizer.numberOfTapsRequired = 1;
    [calloutView addGestureRecognizer:tapGestureRecognizer];

-(void) tapCalloutAction:(id)sender
{
    // do stuff
}

关于ios - 标注注释 View 不可点击中心,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19446823/

相关文章:

objective-c - TextView 处于焦点时隐藏 iPad 键盘的 SDK 安全方法

android - Facebook 和 "image card space"

ios - 无法访问资源文件

php - 如何将文本字段值带入 xcode Obj c 中的其他 viewController?

objective-c - Mac OS X 开发的替代范例

ios - 是否可以在 ios 的 mapView 上集群 MKPolygon

ios - 什么会导致 iPad(第 3 代)在启动时崩溃但在模拟器中工作?

iOS 在 App 关闭时处理多个 APN

ios - 在 map 应用 iOS 上获取方向功能

ios - 向 map 添加多个注释但都显示一些相同的数据