1. 外層UITableView 滾動(dòng)關(guān)鍵代碼
- (void)viewDidLoad {
[super viewDidLoad];
self.canScroll = YES;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeScrollStatus) name:@"BottomTableLeaveTopNotification" object:nil];
}
#pragma mark - Notification
- (void)changeScrollStatus//改變主視圖的狀態(tài)
{
self.canScroll = YES;
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGFloat bottom = [self.tvContent rectForSection:1].origin.y - (IS_IPHONE_X?24:0);
if (scrollView.contentOffset.y>=bottom) {//當(dāng)subcell還沒有滾動(dòng)到
scrollView.contentOffset = CGPointMake(0, bottom);
if (self.canScroll) {
self.canScroll = NO;
//通知子table滾動(dòng)
[[NSNotificationCenter defaultCenter] postNotificationName:@"BottomTableScrollChangedNotification" object:nil userInfo:nil];
}
}else{
if (!self.canScroll) {//子cell沒到頂
scrollView.contentOffset = CGPointMake(0, bottom);
}
}
}
2. 內(nèi)層UITableView/UICollectionView 滾動(dòng)關(guān)鍵代碼
- (void)viewDidLoad {
[super viewDidLoad];
//滾動(dòng)處理
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeScrollStatus:) name:BottomTableScrollChangedNotification object:nil];
}
#pragma mark - Notification
-(void)changeScrollStatus:(NSNotification *)objc
{
_canScroll = YES;
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if (self.canScroll == NO)
{
scrollView.contentOffset = CGPointZero;
}
if (scrollView.contentOffset.y <= 0)
{
self.canScroll = NO;
scrollView.contentOffset = CGPointZero;
//通知外層table滾動(dòng)
[[NSNotificationCenter defaultCenter] postNotificationName:BottomTableLeaveTopNotification object:nil];
}
}
源碼在此* demo