简体   繁体   中英

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!

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

func viewDidLayoutSubviews()

Let me know if this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM