3

What's the difference between UIDeviceOrientation & UIInterfaceOrientation ?

Which one should I use to detect rotation on a UIView?

aryaxt
  • 76,198
  • 92
  • 293
  • 442

2 Answers2

10

UIDeviceOrientation gives you information about the physical device itself while UIInterfaceOrientation tells you about the orientation of the views it is displaying. These do not need to match; when a user uses the orientation lock or if the the device orientation is face up.

You probably want to be checking UIInterfaceOrientation and the rotation methods on UIViewController to determine when views have been or should be rotated.

Jonah
  • 17,918
  • 1
  • 43
  • 70
  • 1
    Things I wish I had known a year ago! I had to work up a whole solution to this problem using the device orientation that worked, but didn't cover a few corner cases. HOURS of headaches... Thank you! – mtmurdock Mar 07 '12 at 22:47
2

UIDeviceOrientation refers to the physical orientation of the device whereas UIInterfaceOrientation refers to the orientation of the user interface.

So what you need to set is the autoResizeMask so that the view is resized correctly when its superview is resized. Set flexibleWidth and flexibleHeight for the view. Check http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIDevice_Class/Reference/UIDevice.html

Also - refer to

UIDEVICE orientation

UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]
Community
  • 1
  • 1
  • Your above code is incorrect. You are assigning the device orientation to a UIInterfaceOrientation variable. Should either be `UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]` or it should be `UIInterfaceOrientation orientation = self.interfaceOrientation` where self is a UIViewController. – mtmurdock Mar 07 '12 at 22:49