我在试图弄清楚为什么导航栏项目不合适时遇到了问题 - 挤到最后。
见https://drive.google.com/file/d/0B8bNRC27tztoTkZwamVlSllMNjA/view 网上没有任何解决此问题的方法。我的视图层次结构是
pageviewcontroller -> navViewController -> VC1
。
我能够解决问题,但删除了这一行
addChildViewController(pageViewController)
在pageviewcontroller类中的但是我需要它才能使pageviewcontroller正常运行。非常感谢任何帮助。
App代表:
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]
}
答案 0 :(得分:0)
感谢对该问题的编辑。如果您仍然发现问题并且不想添加UIBarButtonItem代码段,请按照以下答案,而不是负间距,给出正面的: How to Edit Empty Spaces of Left, Right UIBarButtonItem in UINavigationBar [iOS 7]
这更像是一个黑客攻击。如果您可以发布所请求的代码,我可以给出更明确的答案:)
也要为这个答案提供支持:)