小编Ali*_*sei的帖子

主屏尺寸总是320x480?

我注意到一些奇怪的事情:如果我从iOS应用程序项目中删除所有启动图像/故事板,则UIScreen.main.bounds缩小到320x480,无论实际屏幕大小如何.

我的问题是:我是否需要启动图像/故事板以确保主屏幕的大小正确?

这是一个代码示例:

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

  var window: UIWindow?

  func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

    let screenBounds = UIScreen.main.bounds
    print(String(describing: screenBounds)) // Prints "(0.0, 0.0, 320.0, 480.0)"

    window = UIWindow(frame:screenBounds)
    window!.rootViewController = MyViewController()
    window!.makeKeyAndVisible()

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

这是我的模拟器屏幕(iPhone 8 plus,iOS 11.2):

模拟器的屏幕截图

uikit ios uiscreen

1
推荐指数
1
解决办法
321
查看次数

标签 统计

ios ×1

uikit ×1

uiscreen ×1