ios - 手动创建的 UIWindow 大小错误

标签 ios swift uikit uiwindow uiscreen

我正在学习如何在没有 Interface Builder 的情况下创建 iOS 应用程序(即 Storyboard、xibs 等)。下面是我正在使用的基本应用程序委托(delegate)类。问题是当显示 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
  }
}

Why doesn't the window use the whole screen?

最佳答案

问题原来是我没有启动图像或 Storyboard。出于某种原因,如果没有这个,应用程序默认为 3.5"大小。归功于此评论:A launch storyboard or xib must be provided unless the app requires full screen

关于ios - 手动创建的 UIWindow 大小错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38817725/

相关文章:

ios - 线程安全属性字符串高度计算

ios - ImageView 不遵守约束

ios - Objective-C - 有没有办法将 UIView 属性作为数组?

ios - 从数组中删除使用闭包的监听器

arrays - 如何判断 Int 数组是否按降序排序?不要使用额外的内存

ios - 翻转图像以供按钮使用

iphone - 如何从 iPhone 的图库中删除选定的照片?

swift - 在 ios Swift 中的 Images.xcassets 文件夹中的 Collection View 中显示图像

python - 如何快速不返回加盐密文,而是返回未加盐版本的密文?

ios - 在 iOS 13 上滚动到顶部时,工具栏项目重置为 Storyboard 默认值