2013-10-03 1 views
0

UIInterfaceOrientation이 변경되면 캡처하려고합니다. UIDeviceOrientation을 사용하여 작업하는 방법을 알고 있지만 왼쪽/오른쪽 및 세로 방향을 제외한 모든 것을 방지하려고합니다.장치를 가져 오는 방법 UIInterfaceOrientation

나는 UIDeviceOrientation을 사용하고 있었지만 매번 내놓을 때마다 내 앱에 모든 것이 미쳐 버렸습니다.

그래서 나는 내가 단지 가로 또는 세로 중 볼이

UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]; 

     UIInterfaceOrientation interfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation]; 


     CGFloat screenHeight = [[UIScreen mainScreen] bounds].size.height; 

     CGFloat screenWidth = [[UIScreen mainScreen] bounds].size.width; 

if (interfaceOrientation landscape) { 
      if (orientation == UIDeviceOrientationLandscapeLeft) 
      { 

      } 
      else if (orientation == UIDeviceOrientationLandscapeRight) 
      { 

      } 
     } 

if (interfaceOrientation Portrait) { 


} 

같은 일을하는 방법을 알고 싶어했다.

도움

주시면 감사하겠습니다.

답변

2
if (UIInterfaceOrientationIsLandscape(interfaceOrientation)) { 

} 

이것은 목표 C 함수가 아니라 C 함수입니다.

UIInterfaceOrientation은 enum입니다.

다른 옵션은 다음과 같습니다

// Note that UIInterfaceOrientationLandscapeLeft is equal to UIDeviceOrientationLandscapeRight (and vice versa). 
// This is because rotating the device to the left requires rotating the content to the right. 
typedef NS_ENUM(NSInteger, UIInterfaceOrientation) { 
    UIInterfaceOrientationUnknown   = UIDeviceOrientationUnknown, 
    UIInterfaceOrientationPortrait   = UIDeviceOrientationPortrait, 
    UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown, 
    UIInterfaceOrientationLandscapeLeft  = UIDeviceOrientationLandscapeRight, 
    UIInterfaceOrientationLandscapeRight  = UIDeviceOrientationLandscapeLeft 
}; 

/* This exception is raised if supportedInterfaceOrientations returns 0, or if preferredInterfaceOrientationForPresentation 
    returns an orientation that is not supported. 
*/ 
UIKIT_EXTERN NSString *const UIApplicationInvalidInterfaceOrientationException NS_AVAILABLE_IOS(6_0); 

typedef NS_OPTIONS(NSUInteger, UIInterfaceOrientationMask) { 
    UIInterfaceOrientationMaskPortrait = (1 << UIInterfaceOrientationPortrait), 
    UIInterfaceOrientationMaskLandscapeLeft = (1 << UIInterfaceOrientationLandscapeLeft), 
    UIInterfaceOrientationMaskLandscapeRight = (1 << UIInterfaceOrientationLandscapeRight), 
    UIInterfaceOrientationMaskPortraitUpsideDown = (1 << UIInterfaceOrientationPortraitUpsideDown), 
    UIInterfaceOrientationMaskLandscape = (UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight), 
    UIInterfaceOrientationMaskAll = (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskPortraitUpsideDown), 
    UIInterfaceOrientationMaskAllButUpsideDown = (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight), 
}; 
다음 UIApplication.h 헤더에서

if (interfaceOrientation & (UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight)) { 

}