Search code examples
iosiphoneswiftstoryboarduipageviewcontroller

The gap that appears on swiping UIPageViewController -- Swift


I have created a container for "modul screens" with UIPageViewController. The main problem is a wrong size if set previous screen.

enter image description here

On screenshot you can see that are showed 2 screens instead 1.

For setting a new screen I use

func launchViewControllerC(vc: USBaseVaultStepViewcontroller,
                           step: UIPageViewControllerNavigationDirection,
                           animated: Bool = true) {
    vc.delegate = self

    self.pageController.setViewControllers([vc],
                                           direction: step,
                                           animated: true,
                                           completion: nil)

}

and for the previous screen I use:

func launchPreviousScreen() {
    guard let previousStep = self.currentSetupStep.previousStep() else {
        return
    }

    guard let previousController = self.setupStepViewControllerForStep(previousStep) else {
        return
    }

    self.currentSetupStep = previousStep
    previousController.delegate = self

    self.pageController.setViewControllers([previousController],
                                           direction: UIPageViewControllerNavigationDirection.Reverse,
                                           animated: true,
                                           completion: nil)
}

TIP: It happens when setViewControllers has animated true. Also I have found out that completion block doesn't work properly.


Solution

  • On a storyboard where is located my container with PageViewController I have disabled option Autoresize Subview. And the "gap" during animation disappeared.

    But the description above isn't solution just a clue. The main problem was subHeader that showed on the screen. I was changing height constraint in runtime that is why UIPageViewController didn't know correct size of the screens. I had to separate my screens and I've made Inner screen. I'm using UIPageViewController in UIPageViewController. And for know animation works perfect.