Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the iPhone view's current orientation or the device's last orientation?

In my app an image appears when user shakes the device. There are different images for landscape and portrait mode. If the iPhone's orientation is portrait or landscape, it works fine. But if it is UIDeviceOrientationFaceDown or UIDeviceOrientationFaceUp, the image should depend on the last orientation used, because the view is still displayed for this orientation.

How can I get the last orientation of the device?

like image 950
Knodel Avatar asked Aug 19 '10 14:08

Knodel


People also ask

How do you check orientation on iPhone?

Swipe down from the top-right corner of your screen to open Control Center. Tap the Portrait Orientation Lock button to make sure that it's off. Turn your iPhone sideways.

Where is orientation lock in settings?

Swipe down from the top of the screen to open the Quick settings panel. Look for the screen orientation icon. Depending on your settings, you may need to look for the Portrait, Landscape, or Auto Rotate icon.


2 Answers

I've figured it out! I had to check the status bar's orientation!

[UIApplication sharedApplication].statusBarOrientation
like image 176
Knodel Avatar answered Nov 15 '22 06:11

Knodel


Well in the shouldAutoRotate method of a class it passes in a parameter called interfaceOrientation. This method is called anytime the device orientation changes. You can store this as a variable and the look at it at a later time to determine the last orientation.

 1 = standard portrait
 2 = upsidedown
 3 = button right landscape
 4 = button left landscape. 

Also the call of self.interfaceOrientation will give you the current device orientation.

Hope this at least get you started in the correct direction.

like image 40
E. Criss Avatar answered Nov 15 '22 07:11

E. Criss