Search code examples
iosobjective-ciphoneios10uipageviewcontroller

UIPageViewController duplicates first ViewController behind PageViewController for iOS 10 but behaves normally with a white background for iOS 9.3


I followed this tutorial to create a PageViewController and it works perfectly when I run it on an iOS 9.3 emulator device. However, when I run it on an iOS 10.0 emulator device, it duplicates the first view controller behind the pageViewController - so that when you scroll left on the first slide, you can see the initial viewController peeking out from behind it, and similarly when you scroll right on the last viewController, you can see that same first viewController peek out from behind that too. On the iOS 9.3 device, there is just a white background.

Additional information:

  • I'm using the UIPageViewControllerTransitionStyleScroll so there is that 'bounce' effect (which is where you can see the white on iOS 9.3 and the duplicated viewController on iOS 10)
  • I cannot use another transition style (as some other solutions suggest just using a 'curl' transition)
  • I've already tried UIPageViewController memory leak (see solution by specialvict in that post)
  • Just to be clear, I want a white background behind the pageViewController so that when you scroll left on the first slide or right on the last one, you see just white.

Solution

  • Found the solution. The function used to create and setup the viewController and its subviews were standard and had nothing significantly different to the code from the tutorial above. The problem I had was that I called this function in viewDidLayoutSubviews without checking if the containerView was not perhaps already initialised (containerView being the view that I add the pageController to).

    To check out what is happening, I print a short message to the log when the containerView is initialised. I removed the check if (!self.containerView) and iOS 9 only initialises the containerView once whilst iOS 10 initialises twice. Thus, adding the check if (!self.containerView) before initialising the containerView fixes this problem for 10.