How to make a UIScrollView snap to icons (like App Store: Feature)

后端 未结 4 1663
渐次进展
渐次进展 2020-12-24 10:14

What I want to get is the same behaviour that this scroll view has:

\"App

4条回答
  •  生来不讨喜
    2020-12-24 10:30

    Simple solution, works like App Store, with velocity or without it. kCellBaseWidth — width of cell.

    - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView
                         withVelocity:(CGPoint)velocity
                  targetContentOffset:(inout CGPoint *)targetContentOffset
    {
        NSInteger index = lrint(targetContentOffset->x/kCellBaseWidth);
        targetContentOffset->x = index * kCellBaseWidth;
    }
    

提交回复
热议问题