UIScrollView with “Circular” scrolling

后端 未结 4 2090
挽巷
挽巷 2020-12-03 00:18

I am trying to make \"Circular\" scrolling in my UIScrollView, but unsuccessful.

What I want to do: if uiscrollview reaches end, it should move to start if uiscrollv

4条回答
  •  一向
    一向 (楼主)
    2020-12-03 00:44

    Try to use following code..

    Sample code..

    - (void)scrollViewDidEndDecelerating:(UIScrollView *)sender 
        {
    
            if (scrollView.contentOffset.x == 0) {
                // user is scrolling to the left from image 1 to image n(last image).
                // reposition offset to show image 10 that is on the right in the scroll view
                [scrollView scrollRectToVisible:CGRectMake(4000,0,320,480) animated:NO];// you can define your `contensize` for scrollview
            }
            else if (scrollView.contentOffset.x == 4320) {
                // user is scrolling to the right from image n(last image) to image 1.
                // reposition offset to show image 1 that is on the left in the scroll view
                [scrollView scrollRectToVisible:CGRectMake(320,0,320,480) animated:NO];
            }
        }
    

    Hope, this will help you...

提交回复
热议问题