Search code examples
swiftxcodeuitabbaruipageviewcontrollerswift4.2

How to create a Page View Controller like Instagram homepage that also scrolls Tab Bar?


I want to create a home page like Instagram, that scrolls vertically (with a Navigation Controller, Tab Bar Items, ...) to another View Controller. For example when I swipe left from Instagram home page, it will scroll to direct messages with another Tab Bar Item and the Tab Bar also moves left and is replaced with a new Tab Bar in direct messages View Controller.

enter image description here

I tried to use UIPageViewController but because I use a Tab Bar, when I start scrolling, the Tab Bar remains in its place. How can I achieve the desired behavior?


Solution

  • Since you mentioned that the Tab Bar remains in place even when swiping horizontally, I believe your View Controller hierarchy looks something like this:

    UITabBarController
    └── UIPageViewController
        ├── UIViewController1
        ├── UIViewController2
        ├── .
        ├── .
        ├── .
    

    But you need to put Tab Bar Controller inside the Page View Controller, so your View Controller hierarchy would become like this:

    UIPageViewController
    └── UITabBarController
        ├── UIViewController1
        ├── UIViewController2
        ├── .
        ├── .
        ├── .