How can I make uiscrollview infinite in iOS?

后端 未结 8 1339
天涯浪人
天涯浪人 2020-12-08 01:27

I want to scroll like that 1 2 3 1 2 3

I have some buttons suppose 10 which i want to show on endless scroll.

 numbercolors=[[NSMutableArray alloc         


        
8条回答
  •  粉色の甜心
    2020-12-08 02:09

    Main idea is to reposition your scrollview back to some constant value, when it has been scrolled to some value and then auto-reposition your "1" , "2", "3" items correctly.

    For example - You would have scrollview with contentwidth 5000. By default You set it to position 2500.

    then You simply check in - (void)scrollViewDidCScroll:(UIScrollView *)scrollview - if scrollview.contentoffset.x > 3500 - then decrease it's position to scrollview.contentoffset.x -=1000;

    and the same about other side. This will result in infinite scrolling.

    But content will not follow. So - You would need to implement extra content offset value checking to reorder and reposition correctly "1", "2", "3", items.

    I usually use 3 elements and then dynamically preload necessary gallery image for them.

    If You don't want to re-invent the "wheel" , check out these solutions:

    https://www.cocoacontrols.com/controls/dmcircularscrollview

    https://www.cocoacontrols.com/controls/infinitescrollview

    https://www.cocoacontrols.com/controls/iainfinitegridview

提交回复
热议问题