Paging UIScrollView with different page widths

后端 未结 1 1403
無奈伤痛
無奈伤痛 2020-12-14 02:47

I would like to have a horizontal scrolling UIScrollView with paging enabled. The pages in this scrollview have different widths, so the scrolling distance differs from page

相关标签:
1条回答
  • 2020-12-14 03:26

    it's surely possible, but not so automatically...

    i guess you should implement the UIScrollViewDelegate protocol method:

    - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
    
    }
    

    it's the method called when the user stop to move the finger on the scrollView, you can check inside it the coordinate of your content:

    yourScrollView.contentOffset
    

    and then check which one of your page.x ( register them in an array when you create them, or check the origin of all your view added to the scrollView) is closer to it, then go to the offSet of your page (with animation) calling:

    - (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated
    
    0 讨论(0)
提交回复
热议问题