Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Different behavior between iPhone and iPad

I'm running the same code on an iPhone 6 plus and an iPad Pro and they don't react the same way. A function is called when the device orientation change and then I'm just printing the width of the view with the following code :

override func viewDidLoad(){
    super.vewDidLoad()
    NotificationCenter.default.addObserver(self, selector: #selector(MyClass.rotated), name: NSNotification.Name.UIDeviceOrientationDidChange, object: nil)
}
func rotated(){
    print(self.view.bounds.width)
}

On iPhone I get the width after the rotation but on iPad I get the width before the rotation. Thanks for your help!

like image 306
AW5 Avatar asked Jan 26 '26 16:01

AW5


1 Answers

You can try to get the width in the View Controller Function:

func viewDidLayoutSubviews()

Let me know if this helps!

like image 81
Daniel Pratt Avatar answered Jan 28 '26 08:01

Daniel Pratt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!