UIDeviceOrientation
Refers to the physical orientation of the device whereas UIInterfaceOrientation
refers to the orientation of the user interface.
UIDeviceOrientation
is a property UIDevice
of the class, and there is these possible values:
uideviceorientationunknown-can " t be Determined uideviceorientationportrait- Home button facing Downuideviceorientationportraitupsidedown - Home button facing Upuideviceorientationlandscapeleft - Home button facing Rightuideviceorientationlandscaperight - Home button facing Leftuideviceorientationfaceup -Device is flat, with the screen facing Upuideviceorientationfacedown -Device is flat, with screens facing down
UIInterfaceOrientation
As for, it's a property of an and only UIApplication
contains 4 possibilities which correspond to the Orientat Ion of the status bar:
uiinterfaceorientationportrait == = = Uideviceorientationlandscapeleft
Get device orientation and user interface Orientation
Get device orientation UIDeviceOrientation
:
[[Uidevice Currentdevice] orientation]
Gets the user interface orientation UIInterfaceOrientation
,
Monitoring of device and user interface orientation changes
Device Orientation Change
[[nsnotificationcenter defaultcenter] addobserver:self SE Lector: @selector (handleorientchange:) name:uideviceorientationdidchangenotific ationObject: nil];?- (void) orientationchanged: (Nsnotification *) notification{[self adjustviewsfororientation:[[uiapplication sharedapplication] Statusbarorientation]];}?- (void) Adjustviewsfororientation: (uiinterfaceorientation) Orientation {? Switch(orientation) { Caseuiinterfaceorientationportrait: CaseUiinterfaceorientationportraitupsidedown: {//Load the portrait view }? Break; CaseUiinterfaceorientationlandscapeleft: Caseuiinterfaceorientationlandscaperight: {//load the landscape view } Break; CaseUiinterfaceorientationunknown: Break; }}?
User interface Orientation Change
[[Nsnotificationcenter Defaultcenter] addobserver:self selector: @selector (didchangeorientation:) Name:uiapplicationdidchangestatusbarorientationnotificationObject: nil];?- (void) Didchangeorientation: (Nsnotification *) notification{uiinterfaceorientation orientation=[UIApplication sharedapplication].statusbarorientation;? if(Uiinterfaceorientationislandscape (orientation)) {NSLog (@"Landscape"); } Else{NSLog (@"Portrait") }}
Use Nsnotificationcenter to remember the Remove observer in the Dealloc method
[[Nsnotificationcenter Defaultcenter] removeobserver:self];
Judging whether vertical screen
BOOL isportrait = uideviceorientationisportrait (self.interfaceorientation);
Judging the screen
BOOL Islandscape = self.view.frame.size.width > self.view.frame.size.height;
This method is problematic when controllers is not full-screen.
Sue_zheng
Source:http://www.cnblogs.com/sueZheng/p/4954938.html
iOS device orientation and user interface orientation