为什么UIScreen.bounds在iOS11中不正确 [英] Why are UIScreen.bounds incorrect in iOS11
问题描述
请不要将其标记为重复项.可用线程尚未提供答案.行为仅适用于iOS11.
使用现在的iOS11但仍使用Swift 3将项目从Xcode 8更新到Xcode 9,我有以下经验:
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
)
打印:
UIScreen.main.bounds.width = 414.0
self.view.frame.width = 600.0
该视图应该从屏幕边缘到屏幕边缘.因此,我使用了 UIScreen.main.bounds.width
.但是对于 self.view.frame.width
的实际视图控制器大小而言,该值太小了.
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.
物理设备.使用 UIScreen.main.bounds.width
推荐答案
我有一个类似的问题,错误地获取了 UIScreen.main.bounds
大小.尺寸小于物理屏幕.解决方案是将下一行添加到 info.plst :
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:
键:
Launch screen interface file base name
类型:
String
值:
LaunchScreen
因此,请检查您的 info.plist ,看看其中是否包含此行.如果不是,则添加它.希望这可以帮助. info.plst的屏幕截图
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
这篇关于为什么UIScreen.bounds在iOS11中不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!