以编程方式创建UINavigationController

时间:2019-05-03 03:15:30

标签: ios swift uinavigationcontroller programmatically

我创建了一个非常简单的UINavigationController应用程序。不使用IB,仅创建两个文件AppDelegate.swift和ViewController.swift。但是结果看起来很奇怪。请检查附件图片

我使用XCode 10.2.1。模拟器的屏幕无法完全填充,并且iphone8模拟器的状态栏放置在错误的位置。

the screens can't be filled

AppDelegate.swift:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.
    self.window = UIWindow(frame: UIScreen.main.bounds)
    let homeVC = ViewController(nibName: nil, bundle: nil)
    homeVC.title = "HOME"

    let nav = UINavigationController(rootViewController: homeVC)
    self.window?.rootViewController = nav
    self.window?.makeKeyAndVisible()

    return true
}

ViewController.swift:

class ViewController: UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()
    self.view.backgroundColor = UIColor.yellow
    // Do any additional setup after loading the view.
}

我怎么了?

1 个答案:

答案 0 :(得分:0)

这似乎是iPhone X和其他设备未优化应用的情况。你好吗?由于我没有看到LaunchScreen.storyboard,因此我假设您正在使用图像资产。对此不屑一顾,因为一旦创建了新的屏幕尺寸,您将需要更新应用。

TL:DR对LaunchScreen.storybooard VS Launch Screen File使用Launch Images Source

已编辑:创建LaunchScreen.storyboard并将其设置为Launch Screen文件

enter image description here