2

I am using UIPageViewController to create the introduction pages of my app.

As the gif(I swiped to the 2nd view and swiped back to the 1st view):

enter image description here

My second page's view was not at the correct position initially. It's upper than it should be and dropped down later. However, if I swiped back, the first page's view was correct.

I guess it's because the UIPageViewController didn't load my 2nd view early enough, so the auto layout system was still calculating the position when the 2nd view already appeared. When I swiped back to the 1st view, since the view was already loaded, there was no such issue.(it's just my guess, I am not sure.)

I found I can use 2ndViewController.loadView() as a workaround, but Apple's document discourages programmers to call this method directly. I also found calling this method directly is buggy.

How do I prevent this correctly?

Brian
  • 30,156
  • 15
  • 86
  • 87

2 Answers2

0

If you are setting constraints, fix the view's top space from Superview.

saurabh
  • 6,687
  • 7
  • 42
  • 63
0

In func create view at index, let try my code

func pageTutorialAtIndex(index: Int) ->TestNodeController
{
    let pageContentViewController = self.storyboard?.instantiateViewControllerWithIdentifier("TestNodeController") as! TestNodeController
    pageContentViewController.automaticallyAdjustsScrollViewInsets = false
    pageContentViewController.pageIndex = index
    return pageContentViewController

}