Skip to main content

UIDeviceOrientation vs. UIInterfaceOrientation

We stumbled upon a bug in one of our apps:

- rotate the Homescreen to Landscape
- go to some other screen
- put the device on the table and go back
- the homescreen is all messed up

This behavior was similar with some other View controllers. The problem was in the viewDidAppear where the Interface should be rotated to Layout or Portrait- the UIDevice Orientation was used ( [UIDevice currentDevice].orientation ) an when you put the device on the Table the orientation of the Device is always "UIDeviceOrientationFaceUp". The Problem is that the Device Orientation could be FaceUp in Portrait AND Landscape mode so for this use-case this doesn't give you the proper information.

instead determining the orientation by:
UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation)


you should do this (at least in View controllers) and use the interfaceOrientation property:
UIInterfaceOrientationIsLandscape(self.interfaceOrientation)

Comments