主屏尺寸总是320x480?

时间:2018-01-18 17:50:26

标签: ios uikit uiscreen

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

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

screenshot of the simulator

1 个答案:

答案 0 :(得分:9)

如果您没有任何启动图片,并且您没有启动笔尖或故事板,那么您宣称除了320x480之外您不支持任何屏幕尺寸(在iPhone上) /iPod)。这一直是真的,但是旧的Xcode Projects自动生成了一个支持4"屏幕。如果您使用的是iPhone 6或iPhone 6 Plus,这可能是不可见的,因为如果你有4"屏幕支持,这些设备缩放你的应用程序而不是信件装箱。

我认为信件拳击是为了确保您的用户界面不会被iPhone X的顶级破坏而成为新的默认行为而不是缩放。

根据您支持的屏幕尺寸将启动图像或故事板添加到项目中应解决此问题

相关问题