我注意到一些奇怪的事情:如果我从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):