QQ20171229-092814.gif
首先在自定義的tableview中加入U(xiǎn)IGestureRecognizerDelegate审轮,在初始化方法中加入 :
self.panGestureRecognizer.delegate = self;
然后實(shí)現(xiàn)手勢的代理方法:
- (BOOL)gestureRecognizer:(UIGestureRecognizer*)gestureRecognizer shouldReceiveTouch:(UITouch*)touch {
//判斷tableView是否滑動到最底部(或最頂部,此處最底), round函數(shù):四舍五入
if (round(self.contentOffset.y) == round(self.contentSize.height - self.frame.size.height)) {
// 判斷當(dāng)前View是否是百度地圖的手勢處理視圖TapDetectingView.
if([NSStringFromClass([touch.view class])isEqual:@"TapDetectingView"]){
//若為百度地圖的手勢處理視圖TapDetectingView則tableView的手勢事件不響應(yīng)
return NO;
}
}
return YES;
}
運(yùn)行后發(fā)現(xiàn)地圖上下滑動確實(shí)不跟隨tableview一起動了肥哎,但左右滑動還是會與scrollview沖突:
QQ20171229-093628.gif
于是,給 scrollview 添加代理疾渣,實(shí)現(xiàn) scrollViewDidScroll:這個(gè)方法:
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
// 只有當(dāng)tableview滑到最低部時(shí)才禁用scrollview
if (round(_tableView.contentOffset.y) == round(_tableView.contentSize.height - _tableView.frame.size.height)) {
// 當(dāng)滑動的范圍小于屏幕寬度時(shí)篡诽,禁止scrollView滑動
if (scrollView.contentOffset.x < SCREEN_WIDTH) {
self.scrollView.scrollEnabled = NO;
}
else {
self.scrollView.scrollEnabled = YES;
}
}
// 其他照舊
else{
self.scrollView.scrollEnabled = YES;
}
}
運(yùn)行后發(fā)現(xiàn)地圖上下滑動、左右滑動均不受影響了:
QQ20171229-100049.gif