问题
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