Home > Software design >  UIScreen.main.bounds returning incorrect size
UIScreen.main.bounds returning incorrect size

Time:01-16

UIScreen.main.bounds.width and UIScreen.main.bounds.height are both wrong. It's returning 414x736 but it should be about 360x640. Device: iPhone 8 Plus.

CodePudding user response:

iPhone [Any] Plus native rendering resolutions are downsampled by ÷1.15 because screens didn't have enough pixels to show @3x until iPhone X arrived.

Screen resolution is 360x640 physical points but screen rendering is 414x736 software points. That only happens on Plus models.

414 ÷ 1.15 = 360
736 ÷ 1.15 = 640

Check out this: enter image description here

CodePudding user response:

It depends on when you call the function.

You have to call this after View Appear fully.

override func viewDidLoad() { // Or viewDidAppear()
{
    let frame = self.view.bounds; // or UIScreen.main.bounds also works
}

You will get different value if you call the function on viewWillAppear.

  •  Tags:  
  • Related