2013-10-03 3 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 - это перечисление.

Другой вариант был бы:

if (interfaceOrientation & (UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight)) { 

} 

Из UIApplication.h заголовка:

// 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), 
}; 
Смежные вопросы