手动创建的UIWindow是错误的大小

mac*_*osh 8 uikit uiwindow ios uiscreen swift

我正在学习如何在没有Interface Builder(即故事板,xib等)的情况下创建iOS应用程序.下面是我正在使用的基本应用程序委托类.问题是,显示时UIWindow不会耗尽设备的全屏(参见附件截图).这发生在我测试的所有设备和模拟器上.为什么不使用全屏?

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
  lazy var window: UIWindow? = {
    debugPrint("AppDelegate: Creating Window")

    let screen: UIScreen = UIScreen.mainScreen()
    let window: UIWindow = UIWindow.init(frame: screen.bounds)

    window.backgroundColor = UIColor.whiteColor()

    return window
  }()

  lazy var rootViewController: ShapesViewController = {
    debugPrint("AppDelegate: Creating Root View Controller")

    let rootViewController = ShapesViewController.init(nibName: nil, bundle: nil)

    return rootViewController
  }()

  func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool {
    debugPrint("AppDelegate: applicationWillEnterForeground")

    window?.rootViewController = rootViewController
    window?.makeKeyAndVisible()

    return true
  }
}
Run Code Online (Sandbox Code Playgroud)

为什么窗口不使用整个屏幕?

mac*_*osh 11

问题是我没有发布图像或故事板.由于某些原因没有这个,应用程序默认为3.5"大小.相信此评论:必须提供启动故事板或xib,除非应用程序需要全屏

  • 引用 Matt Neuberg(了不起的技术作家!)的书 [“iOS 9 Programming Fundamentals with Swift”](http://shop.oreilly.com/product/0636920044345.do):`启动屏幕界面文件的存在*Info.plist* 中的 base name` 键告诉系统您的应用程序本机在较新的设备类型上运行,例如 iPhone 6 和 iPhone 6 Plus。没有它,您的应用程序将被放大显示……您将无法获得您有权获得的所有像素…… (2认同)

dvd*_*blk 2

这总是对我有用(尽管我没有看到任何明显的区别)。您介意也分享您的 ShapesViewController 代码吗?

更新至swift 4.2

var window: UIWindow?

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    window = UIWindow(frame: UIScreen.main.bounds)
    window?.rootViewController = ViewController()
    window?.makeKeyAndVisible()
    return true
}
Run Code Online (Sandbox Code Playgroud)