tableView中嵌套tableView的滑動(dòng)解決方案。
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer;
先看這個(gè)方法攒菠,這個(gè)方法是支持多手勢(shì)交互的。
我這里用的對(duì)于兩個(gè)tableview通信歉闰,用的是通知辖众。
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeScrollStatus) name:@"leaveTop" object:nil];
首先分析主tableView.
結(jié)構(gòu)是這樣的卓起。2個(gè)section。第一個(gè)section有兩個(gè)cell凹炸,第二個(gè)section有一個(gè)cell然后里面嵌套了tableView戏阅。
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
CGFloat bottom = [self.tableView rectForSection:1].origin.y;
// NSLog(@"%lf",bottom);
if (scrollView.contentOffset.y>=bottom) {//當(dāng)subcell還沒有滾動(dòng)到
scrollView.contentOffset = CGPointMake(0, bottom);
if (self.canScroll) {
self.canScroll = NO;
self.subcell.vcCanScroll = YES;
NSLog(@"11111111111");
}
}else{
if (!self.canScroll) {//子cell沒到頂
scrollView.contentOffset = CGPointMake(0, bottom);
NSLog(@"222222222222");
}
}
}
獲取第二個(gè)section在tableview中的位置,當(dāng)subtableview滾動(dòng)的時(shí)候啤它,保持scrollView.contentOffset.y為第二個(gè)section的y值奕筐。
然后我們?cè)賮砜磗ubtableview中
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
// NSLog(@"%lf",scrollView.contentOffset.y);
if (!self.vcCanScroll) {
scrollView.contentOffset = CGPointZero;
}
if (scrollView.contentOffset.y <= 0) {
if (!self.fingerIsTouch) {
return;
}
self.vcCanScroll = NO;
scrollView.contentOffset = CGPointZero;
[[NSNotificationCenter defaultCenter] postNotificationName:@"leaveTop" object:nil];//到頂通知父視圖改變狀態(tài)
}
}
首先第一點(diǎn),當(dāng)vccanscroll為false的情況下变骡,subtableview的scrollview.contenoffset一直未0.
當(dāng) scrollview.contenoffset .y大于0的情況下离赫,正常滾動(dòng)。
當(dāng) scrollview.contenoffset .y小于等于0的情況下塌碌,發(fā)送通知渊胸,通知主tableView可以滾動(dòng)。
以上就是重點(diǎn)內(nèi)容台妆。