问题描述: scrollview上添加了百度地图,百度地图的拖动与scrollview的上下拖动同时发生,左右拖动地图可以正常显示,但是上下拖动地图的时候,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;
}
}
实现后的效果