A UIScrollView
,UITableView
的超类,可以是一个悲惨的生物。有太多的行为被编入其中,有时看起来在纸上似乎是一个简单的命题可能很难。除此之外,这个是一个表视图,它变得更糟。
如果你有决心使用UITableView
的tableFooterView
属性来做到这一点,我已经使用了有限的(非常)成功:
这些UIScrollViewDelegate
方法,您的视图控制器可能已经表视图的委托。
- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView{
UIView *tableViewFooter = _tableView.tableFooterView;
CGFloat maxContentOffsetY = tableViewFooter.frame.origin.y - scrollView.frame.size.height;
if (scrollView.contentOffset.y > maxContentOffsetY){
//if (targetPoint.y > maxContentOffsetY){
[scrollView setContentOffset:CGPointMake(0, maxContentOffsetY) animated:YES];
}
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{ // called when scroll view grinds to a halt
// Check offset and correct if we landed below the correct offset
UIView *tableViewFooter = _tableView.tableFooterView;
CGFloat maxContentOffsetY = tableViewFooter.frame.origin.y - scrollView.frame.size.height;
if (scrollView.contentOffset.y > maxContentOffsetY){
[scrollView setContentOffset:CGPointMake(0, maxContentOffsetY) animated:YES];
}
}
我会建议简单地向您的视图控制器的视图属性添加一个渐变。这样,当表格滚动出屏幕时,你会看到它后面的渐变。然后你将获得大部分你想要的免费行为。