self.bgScrollView.bounces = NO; ///和后边bottomCellOffset 正好相反 CGFloat maxH = (Screen_Height - self.bgScrollView.tableViewBottomFloat - Screen_NAV_Height ) * 0.7 - 20; CGFloat tempTableViewOffsetY = maxH; ///重新设置tv高度 [self.bgScrollView.tableView mas_updateConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.bgScrollView.headerButton.mas_bottom); make.height.mas_equalTo(tempTableViewOffsetY); make.left.bottom.right.equalTo(self.carInfoView); }];
/// table能不能滚动 @property (nonatomic, assign) BOOL canScroll; /// scroll能不能滚动 @property(assign, nonatomic) BOOL superCanScroll;
自定义view 的init 方法 或者vc的viewDidLoad 方法 self.canScroll = NO; self.superCanScroll = YES;
实现代理
/// 子视图滚动时候,同时响应滚动手势。 - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { return YES; }
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{ //tableView 滚动处理 if (scrollView == self.tableView){ NSLog(@"tabelview >>>>>>> 滚动 == %.2F",scrollView.contentOffset.y); if (!self.canScroll) { scrollView.contentOffset = CGPointZero; } if (scrollView.contentOffset.y < 0 ) { scrollView.contentOffset = CGPointZero; self.superCanScroll = YES; self.canScroll = NO; } }else{ /* 当 底层滚动式图滚动到指定位置时, 停止滚动,开始滚动子视图 20 :self.bgScrollView.headerButton 的高度 10:底部bottom 高度 */ // CGFloat bottomCellOffset = (Screen_Height - self.tableViewBottomFloat - Screen_NAV_Height - 20) * 0.3; // CGFloat bottomCellOffset = (Screen_Height - self.tableViewBottomFloat - Screen_NAV_Height ) * 0.3 + 20; CGFloat bottomCellOffset = (Screen_Height - self.tableViewBottomFloat - Screen_NAV_Height ) * 0.3 + 10; ///这个是外边tableview的高度 if (scrollView.contentOffset.y >= bottomCellOffset) { scrollView.contentOffset = CGPointMake(0, bottomCellOffset); if (self.superCanScroll) { self.superCanScroll = NO; self.canScroll = YES; } }else{ if (!self.superCanScroll) {//子视图没到顶部 scrollView.contentOffset = CGPointMake(0, bottomCellOffset); } } } }