2012-03-11 2 views
0

Кто-нибудь знает, как программно определить ориентацию iPad при запуске приложения.Определить ориентацию iPad при запуске приложения

Я использую следующий механизм.

- (void) detectDeviceInitialOrientation 
{ 
    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; 

    MyAppDelegate *appDelegate=(MyAppDelegate*)[[UIApplication sharedApplication] delegate]; 

    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]; 

    if (UIDeviceOrientationIsPortrait(orientation)) { 
     appDelegate.orintation = PORTRAIT; 
    } 
    else if (UIDeviceOrientationIsLandscape(orientation)) { 
     appDelegate.orintation = LANDSCAPE; 
    } 
} 

Но он не может определить ориентацию устройства, когда он лежит параллельно полу. Итак, я ищу другое решение. Пожалуйста, помогите ......

ответ

1

Посмотрите на UIDeviceOrientation enum в документах.

typedef enum { 
    UIDeviceOrientationUnknown, 
    UIDeviceOrientationPortrait, 
    UIDeviceOrientationPortraitUpsideDown, 
    UIDeviceOrientationLandscapeLeft, 
    UIDeviceOrientationLandscapeRight, 
    UIDeviceOrientationFaceUp, 
    UIDeviceOrientationFaceDown 
} UIDeviceOrientation; 

Обратите внимание, что это определяет UIDeviceOrientationFaceUp и UIDeviceOrientationFaceDown. К сожалению, нет встроенной проверки того, находится ли устройство в одной из этих ориентаций, например, для портретной или альбомной ориентации. Тем не менее, вы можете сделать проверку себя с помощью простого оператора if. Что-то вроде этого:

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; 

UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]; 

if (orientation == UIDeviceOrientationFaceUp || orientation == UIDeviceOrientationFaceDown) { 
    // device is flat on the ground 
} 
Смежные вопросы