Equivalent to the Android's ViewPager on iOS? Swipe/flip through pages of data

前端 未结 5 1213
夕颜
夕颜 2021-01-30 06:51

On Android there\'s neat way to browse between several pages of data with the same layout by using ViewPager and Fragments. User swipes left or right, and the pages change. Ther

相关标签:
5条回答
  • 2021-01-30 07:17

    You can implement it your own using following idea.

    Suppose that we wish to infinitely loop through 3 items(cells) - C0, C1, C2, we can generate dummy cells at the left and right side of center cells, the result as follows,

    C0 C1 C2 [C0 C1 C2] C0 C1 C2

    Cells in bracket are cells we see through device screen, and if we scroll to left,

    C0 [C1 C2 C0] C1 C2 C0 C1 C2

    at this moment, force contentOffset to point right side of given dummy cells,

    C0 [C1 C2 C0] C1 C2 C0 C1 C2 -> C0 C1 C2 C0 [C1 C2 C0] C1 C2

    It will works in same mechanism when you scroll it to right.

    In my solution below, setting item view width to equal to its parent view will solve your problem.

    https://github.com/DragonCherry/HFSwipeView

    If you just wanna simply check how it works, click link below and "tap to play".

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

    Just using pagingEnabled option in UIScrollView may work in case of full-sized cell item, but it will not work properly if you want to set narrower width of content item than its parent(scroll) view. Please check this feature by referring to cocoacontrols sample for "Sync" or "Edge Preview".

    0 讨论(0)
  • 2021-01-30 07:24

    Use a UIScrollView with the pagingEnabled property set to YES. Typically a UIPageControl is used along with it.

    If you Google for "UIScrollView paging", you can find many tutorials and examples. Apple provides a PageControl sample program.

    iOS doesn't provide any sort of adapter-like class, but here is a tutorial that explains how to implement "virtual pages" so that you don't have to instantiate all the pages at once: http://cocoawithlove.com/2009/01/multiple-virtual-pages-in-uiscrollview.html

    0 讨论(0)
  • 2021-01-30 07:27

    You should look at UIPageViewController. Its available since iOS 5.

    0 讨论(0)
  • 2021-01-30 07:35

    visit https://github.com/vowed21/HWViewPager

    It may help you.

    Inherited UICollectionView.

    Reuseable Cell, (likely Android's Adapter)

    AND enable Preview part of left, right side.

    0 讨论(0)
  • 2021-01-30 07:39

    I've created a custom control for iOS which acts similar to android's viewPager. You can check this out here.

    0 讨论(0)
提交回复
热议问题