Search code examples
iosuipageviewcontroller

How can I reduce the size of iOS view Paging range?


Recently, I made a project which needs to use UIPageViewController.

First, I made one UIPageVC and two normal UIVCs.(VC1, VC2)

So two normal VCs are controlled by the UIPageVC.

And then, I complete the vertical view paging successfully (not page curl mode, just scroll mode)

If I swipe down, than I can see the view change VC2 from VC1, and vice versa

Well, What i want to do is this.

1 I set the VC1 size to small, so let a portion of the VC2 can be seen.

[2] If I swipe down(or up?) change the current view to the entire VC2

[3] and swipe returning, 1 state comes back

The following picture can help you to understand my explanation.

enter image description here

How can I make this?

IS there a any way by controlling Storyboard or code?

Plz let me know :)


Solution

  • You can do this fairly easily using a normal UIScrollView instead of a UIPageViewController.

    • Add FirstVC view to the scroll view
    • constrain its top, leading and trailing to the scroll view
    • constrain its width to the scroll view's width
    • constrain its height to the scroll view's height minus the amount of VC2 you want visible

    then

    • add SecondVC view to the scroll view
    • constrain its top to the bottom of FirstVC's view
    • constrain its leading and trailing to the scroll view
    • constrain its width to the scroll view's width
    • constrain its height to the scroll view's full height
    • constrain its bottom to the bottom of the scroll view

    and enable paging on the scroll view.

    You can do all of this in IB / Storyboard, but working with large scroll content can be cumbersome. Since you already have the two parts in separate view controllers (if I understood your description correctly), it's easier to set the constraints in code.

    I've posted a full working example at: https://github.com/DonMag/YetAnotherScrollExample