꼼시월드

ios 기기의 회전 값 구하기 본문

iOS

ios 기기의 회전 값 구하기

꼼시 2014. 1. 21. 13:38

출처 : http://stackoverflow.com/questions/5559652/how-do-i-detect-the-orientation-of-the-device-on-ios



if UIViewController:

 
if (UIDeviceOrientationIsLandscape(self.interfaceOrientation))
{
    // 
}


if UIView:

 
if (UIDeviceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation))
{
    //
}


UIDevice.h:

 
#define UIDeviceOrientationIsPortrait(orientation)  ((orientation) == UIDeviceOrientationPortrait || (orientation) == UIDeviceOrientationPortraitUpsideDown)
#define UIDeviceOrientationIsLandscape(orientation) ((orientation) == UIDeviceOrientationLandscapeLeft || (orientation) == UIDeviceOrientationLandscapeRight)


add this code to xxx-Prefix.pch then you can use it anywhere:

 
// check device orientation
#define dDeviceOrientation [[UIDevice currentDevice] orientation]
#define isPortrait  UIDeviceOrientationIsPortrait(dDeviceOrientation)
#define isLandscape UIDeviceOrientationIsLandscape(dDeviceOrientation)
#define isFaceUp    dDeviceOrientation == UIDeviceOrientationFaceUp   ? YES : NO
#define isFaceDown  dDeviceOrientation == UIDeviceOrientationFaceDown ? YES : NO


usage:

 
if (isLandscape) { NSLog(@"Landscape"); }



Comments