iOS device orientation and user interface orientation

Source: Internet
Author: User

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

UIDeviceOrientationis 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.