I am having issues trying to figure why navigation bar items are out of place--squeezed to the ends.
see https://drive.google.com/file/d/0B8bNRC27tztoTkZwamVlSllMNjA/view There isn't anything online that address this. My view hierarchy is
pageviewcontroller -> navViewController -> VC1
.
I am able to solve the problem but removing this line
addChildViewController(pageViewController)
in the pageviewcontroller class but I need that for the pageviewcontroller to operate properly. Any help on this is greatly appreciated.
App delegate:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
let PageVC = PageViewController()
window = UIWindow(frame: UIScreen.main.bounds)
window!.rootViewController = PageVC
window!.makeKeyAndVisible()
return true
}
Full pageviewcontroller code:
import UIKit
class PageViewController: UIPageViewController, UIPageViewControllerDataSource, UIPageViewControllerDelegate{
var viewControllerList = [UIViewController]()
override func viewDidLoad() {
super.viewDidLoad()
let vc1 = IntroViewController()
let vc2 = CamViewController()
let navigationController = UINavigationController(rootViewController: vc1)
let navigationController2 = UINavigationController(rootViewController: vc2)
viewControllerList = [navigationController,navigationController2]
self.dataSource = self
self.delegate = self
let firstViewController = viewControllerList.first
self.setViewControllers([firstViewController!], direction: .forward, animated: true, completion: nil)
}
func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? {
guard let vcIndex = viewControllerList.index(of: viewController) else {return nil}
let previousIndex = vcIndex - 1
guard previousIndex >= 0 else {return nil}
guard viewControllerList.count > previousIndex else {return nil}
return viewControllerList[previousIndex]
}
func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? {
guard let vcIndex = viewControllerList.index(of: viewController) else {return nil}
let nextIndex = vcIndex + 1
guard viewControllerList.count != nextIndex else { return nil}
guard viewControllerList.count > nextIndex else { return nil }
return viewControllerList[nextIndex]
}