scrollview 加百度地图 手势冲突解决办法

****解决方法****:

  • 使用UIGestureRecognizerDelegate 代理方法

  • 给scrollview 添加一个手势

UIGestureRecognizer *gestur = [[UIGestureRecognizer alloc]init];
    gestur.delegate=self;
    [self.scrollview addGestureRecognizer:gestur];
  • 给百度地图添加手势
_vMap = [[BMKMapView alloc] initWithFrame:CGRectMake(15, 0, SCREEN_WIDTH - 30, 200)];
/** 注意百度地图的缩放拖动要打开*/
    _vMap.zoomEnabled = YES;
    _vMap.scrollEnabled = YES;
    _vMap.delegate = self;
    [vContent addSubview:_vMap];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onClickBtnLoction:)];
    tap.delegate = self;
    vContent.userInteractionEnabled = YES;
    [_vMap addGestureRecognizer:tap];
  • 实现代理方法
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
   //在这里判断是百度地图的view 既可以实现手势拖动 scrollview 的滚动关闭
    if ([gestureRecognizer.view isKindOfClass:[BMKMapView class]] ){
       self.scrollview.scrollEnabled = NO;
        return YES;
    }else{
        
        self.scrollview.scrollEnabled = YES;
        return NO;
    }
    
}
上一篇:ScrollView中自定义View不显示


下一篇:Java开发技术总结!什么是分布式系统,如何学习分布式系统