Why are UIScreen.bounds incorrect in iOS11

妖精的绣舞 提交于 2020-07-18 19:00:48

问题


Please don't mark as duplicate. Available threads haven't provided an answer. Behavior is iOS11 only.

Updating a project from Xcode 8 to Xcode 9, using now iOS11 but still Swift 3, I have the following experience:

    print("UIScreen.main.bounds.width = \(UIScreen.main.bounds.width)")
    print("self.view.frame.width = \(self.view.frame.width)")

    let rect = CGRect(

        x: 0,
        y: 0,
        width: UIScreen.main.bounds.width,
        height: UIScreen.main.bounds.height * 0.25

    )

prints:

UIScreen.main.bounds.width = 414.0
self.view.frame.width = 600.0

The view is supposed to be from screen edge to screen edge. Therefore I have used UIScreen.main.bounds.width. But the value far too small for the actual view controller size of self.view.frame.width.

Why is that? What am I missing? Help is very appreciated.

Physical device. Same behavior using UIScreen.main.bounds.width


回答1:


I had a similar problem with incorrect fetching of UIScreen.main.bounds size. The size was less than a physical screen. The solution was to add the next line into info.plst:

Key:

Launch screen interface file base name

Type:

String

Value:

LaunchScreen

So check your info.plist to see if it contains this line. If it's not, just add it. Hope this helps. screen shot of info.plst



来源:https://stackoverflow.com/questions/46495605/why-are-uiscreen-bounds-incorrect-in-ios11

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!