swift - 为什么在第一次启动时我的导航栏在状态栏下面

标签 swift ipad uinavigationcontroller uikit ios10

为什么当我用空 View Controller 创建导航 Controller 时,我收到导航栏的奇怪行为?

这就是我创建导航 Controller 的方式。

init(
    window: UIWindow,
    keystore: Keystore,
    navigationController: UINavigationController = UINavigationController()
) {
    self.navigationController = navigationController
    self.keystore = keystore
    super.init()
    window.rootViewController = navigationController
    window.makeKeyAndVisible()
}

比我更简单:

func start() {
    let x = UIViewController()
    x.view.backgroundColor = UIColor.red
    navigationController.setViewControllers([x], animated: true)
}

我收到: enter image description here 但在下一次应用启动时一切正常。

enter image description here

最佳答案

可能是这种情况,因为您在应用已经启动后设置了 NavigationController。

我建议在您的 AppDelegate 中设置 NavigationController。

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        window = UIWindow(frame: UIScreen.main.bounds)

        let firstViewController = UIViewController()
        let navigationController = UINavigationController(rootViewController: firstViewController)

        window?.rootViewController = navigationController
        window?.makeKeyAndVisible()
        return true
    }
}

关于swift - 为什么在第一次启动时我的导航栏在状态栏下面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48063691/

相关文章:

iphone - 仅对 subview 启用 UserInteraction

objective-c - 阻止导航 Controller 导航并要求用户确认

ios - 如何设置右侧导航栏按钮标题

swift - 如何将库导入 CLI 中使用的 swift 代码?

ios - 呈现 App Store 产品 View Controller 变得不可逆转

iphone - iOS 5.0 模态视图不旋转( Storyboard)

xcode - iOS-在具有参数的按钮上调用选择器

ios - UINavigationController + 状态栏框架的CGRect

ios - Swift json 一些带引号的键有些没有

swift - 如何将 UInt8 转换为字节 Swift 4