UITableView 繼承 UIScrollView,可透過 UIScrollViewDelegate 監聽滾動狀態。
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
CGFloat offsetY = scrollView.contentOffset.y;
CGFloat maxOffset = scrollView.contentSize.height - scrollView.bounds.height;
if (offsetY >= maxOffset) {
// 已滾至底部,鎖定 bouncing
scrollView.bounces = NO;
} else if (offsetY <= 0) {
// 頂部區域,允許下拉
scrollView.bounces = YES;
}
}
UIRefreshControl (iOS 6+) 內建下拉刷新,自動處理頂部彈性。tableView:willDisplayCell:forRowAtIndexPath: 觸發分頁請求,而非依賴 bounce。頻繁切換 bounces 可能造成視覺閃爍,建議在 scrollViewWillEndDragging 中配合 decelerationRate 微調,或採用成熟第三方庫 (MJRefresh) 統一處理。