問題描述: scrollview上添加了百度地圖,百度地圖的拖動與scrollview的上下拖動同時發(fā)生,左右拖動地圖可以正常顯示,但是上下拖動地圖的時候,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];
- 實現(xiàn)代理方法
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
//在這里判斷是百度地圖的view 既可以實現(xiàn)手勢拖動 scrollview 的滾動關(guān)閉
if ([gestureRecognizer.view isKindOfClass:[BMKMapView class]] ){
self.scrollview.scrollEnabled = NO;
return YES;
}else{
self.scrollview.scrollEnabled = YES;
return NO;
}
}
實現(xiàn)后的效果