主屏幕尺寸总是 320x480? [英] Main screen size is always 320x480?

查看:32
本文介绍了主屏幕尺寸总是 320x480?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I noticed something weird: if I delete all launch images/storyboards from an iOS app project, then UIScreen.main.bounds shrink to 320x480, regardless of an actual screen size.

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

My question is: do I need a launch image/storyboard to make sure that the size of the main screen is correct?

这是一个代码示例:

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):

And here is my simulator's screen (iPhone 8 plus, iOS 11.2):

推荐答案

如果您没有任何启动图像,并且您没有启动笔尖或故事板,那么您就是在声明您不支持任何除了 320x480 以外的屏幕尺寸(在 iPhone/iPod 上).这一直是正确的,但较旧的 Xcode 项目会自动生成一个 png 以支持 4" 屏幕.如果您使用过 iPhone 6 或 iPhone 6 Plus,这可能是不可见的,因为如果您拥有支持 4" 屏幕的默认图像,这些设备会缩放您的应用而不是将它们装箱.

If you don't have any launch images, and you don't have a launch nib or storyboard, then you are declaring that you don't support any screen sizes aside from 320x480 (on iPhone/iPod).This has always been true but older Xcode Projects automatically generated a png to support 4" screens. This may have been invisible if you've used an iPhone 6 or iPhone 6 Plus, because if you had the default image for 4" screen support, these devices scaled your app rather than letter boxing them.

我认为信箱是为了确保您的 UI 不会被 iPhone X 的一流破坏,并成为新的默认行为而不是缩放.

I assume the letter boxing is to ensure your UI won't get wrecked by iPhone X's top notch and became the new default behavior instead of scaling.

将启动图像或故事板添加到您支持的屏幕尺寸的项目中应该可以解决这个问题

Adding launch images or storyboards to your project for the screen sizes you support should resolve this

这篇关于主屏幕尺寸总是 320x480?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆