UINavigationbar 项目错位

UINavigationbar Items out of position

我在尝试弄清楚为什么导航栏项目不合适——被挤到尽头时遇到了问题。

https://drive.google.com/file/d/0B8bNRC27tztoTkZwamVlSllMNjA/view 网上没有任何内容可以解决这个问题。我的视图层次结构是

pageviewcontroller -> navViewController -> VC1

我能够解决问题,但删除这一行

addChildViewController(pageViewController)

在 pageviewcontroller class 但我需要 pageviewcontroller 才能正常运行。非常感谢对此的任何帮助。

应用委托:

 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
    }

完整的 pageviewcontroller 代码:

  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]

    }

感谢您对问题的编辑。如果您仍然发现问题并且不想添加 UIBarButtonItem 代码段,请按照以下答案进行操作,但不要使用负间距,而是使用正间距How to Edit Empty Spaces of Left, Right UIBarButtonItem in UINavigationBar [iOS 7]

这更像是一个 hack。如果您可以post请求的代码片段,我可以给出更清晰的答案:)

也请为该答案点赞:)