Content pushed down in a UIPageViewController with UINavigationController

后端 未结 15 632
暗喜
暗喜 2020-12-12 18:05

UPDATE 2

I\'ve been running and testing my app in the iOS Simulator using a 4-inch device. If I run using a 3.5-inch device the label doesn\'t jump.

相关标签:
15条回答
  • 2020-12-12 18:50

    As @djibouti33 already posted:

    a pageViewController couldn't properly lay out it's child view controller initially if it contained a scroll view. by the time we're in layoutSubviews, pageViewController seems to have gotten it's bearings and everything is laid out just fine

    By waiting for layoutSubViews to load before setting any viewControllers to the UIPageViewController was the only thing that worked for me.

    override func viewDidLoad() {
        super.viewDidLoad()
        self.pageViewController = self.storyboard?.instantiateViewController(withIdentifier: "yourPageViewController") as? UIPageViewController       
        self.pageViewController?.dataSource = self
    
        pageViewController?.automaticallyAdjustsScrollViewInsets = false    
        self.pageViewController?.view.frame = CGRect(x: 0, y: 0, width: view.frame.size.width, height: view.frame.height)       
        self.addChildViewController(self.pageViewController!)        
        self.view.addSubview((self.pageViewController?.view)!)       
        self.pageViewController?.didMove(toParentViewController: self)
    }
    
    
    override func viewDidLayoutSubviews() {
        let startVC = self.viewControllerAtIndex(index: 0) as infoDataViewController     
        let viewControllers = NSArray(object: startVC)    
        self.pageViewController?.setViewControllers(viewControllers as? [UIViewController], direction: .forward, animated: true, completion: nil)
    }
    
    0 讨论(0)
  • 2020-12-12 18:51

    Just uncheck Under Top Bars for both: UIPageViewController and your custom PageContentViewController:

    0 讨论(0)
  • 2020-12-12 18:52

    Initially my view controller hierarchy looked like this:

    -- UINavigationController
      -- MyContainerViewController
        -- UIPageViewController
          -- MyDetailViewController
    

    I set it up this way so MyContainerViewController could manage a toolbar. I narrowed my problem down to MyContainerViewController, and then it occurred to me that I don't even need it if I subclass UIPageViewController. Now my hierarchy looks like this:

    -- UINavigationController
      -- MyPageViewController
        -- MyDetailViewController
    

    MyPageViewController manages it's toolbar, and everything works as expected, both on a 4-inch and 3.5-inch device.

    0 讨论(0)
提交回复
热议问题