zoukankan      html  css  js  c++  java
  • 高德 ios 自定义气泡添加点击事件无效问题

    在使用高德地图sdk开发的时候,需要自定义气泡吹出框,发现气泡添加的点击事件或者button都没响应.

    原因:自定义的气泡是添加到大头针上的,而大头针的size只有下面很小一部分,所以calloutView是在大头针的外面的。
    而 iOS 按钮超过父视图范围是无法响应事件的处理方法。

    解决办法:

    在CustomAnnotationView.m( @interface CustomAnnotationView : MAAnnotationView

    )中重写hittest方法:

    - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
        UIView *view = [super hitTest:point withEvent:event];
        if (view == nil) {
            CGPoint tempoint = [self.calloutView.navBtn convertPoint:point fromView:self];
            if (CGRectContainsPoint(self.calloutView.navBtn.bounds, tempoint))
            {
                view = self.calloutView.navBtn;
            }
        }
        return view;
    }

    这里的self.calloutView.navBtn 就是你需要点击的按钮

    亲测可用.

  • 相关阅读:
    实现可折叠的列表
    ajax知识点补充
    Ajax 完整教程
    从页面左边飞入页面动画效果
    文字闪烁
    点击按钮之后等待60秒
    [SCOI2016]萌萌哒
    [HNOI2011]卡农
    [NOI2015]寿司晚宴
    【bzoj 3489】A simple rmq problem
  • 原文地址:https://www.cnblogs.com/bug-sniper/p/5236204.html
Copyright © 2011-2022 走看看