Demo中實現的效果是仿照滴滴出行頁面的效果。
1.上拉或下拉可回彈
2.可以將列表不斷上拉,直至看到列表最底部內容
3.列表上拉直至列表內容超出屏幕範圍後,然後不斷下拉,下拉過程中,當拉到列表頂部內容時,列表頂部內容會吸附在屏幕頂端
效果圖如下所示:
demo中的核心代碼:
1.-(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
2.- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset{
CGFloat offsetY = scrollView.contentOffset.y;
BOOL decelerate = (velocity.y != 0); //velocity.y = 0 表示無減速
BOOL isUp = velocity.y > 0; //velocity.y > 0 表示向上,velocity.y < 0表示向下
//有減速
if (decelerate)
{
//禁止慣性滾動
dispatch_async(dispatch_get_main_queue(), ^{
});
return;
}
//無減速
if (!decelerate)
{
}
}
想要下載Demo,點這裏 --> 仿滴滴出行Demo
如果您感覺有用,記得 star 一下喲!😝