Подтвердить что ты не робот

Как проверить ориентацию устройства программно в iPhone?

Возможный дубликат:
ориентация iPhone

Как проверить ориентацию устройства в любой момент времени программно в iPhone?

Спасибо.

4b9b3361

Ответ 1

Вот макросы UIDeviceOrientationIsLandscape и UIDeviceOrientationIsPortrait

поэтому достаточно проверить отдельно, вы можете сделать это вот так...

   if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation))
    {
         // code for landscape orientation      
    }

ИЛИ

    if (UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation))
    {
         // code for Portrait orientation       
    }

Ответ 2

Попробуйте.

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

if ( ([[UIDevice currentDevice] orientation] ==  UIDeviceOrientationPortrait)  )
{
   // do something for Portrait mode
}
else if(([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight) || ([[UIDevice currentDevice] orientation] == UIInterfaceOrientationLandscapeLeft))
{
   // do something for Landscape mode
}

Ответ 3

Попробуйте также:

UIInterfaceOrientationIsPortrait(orientation)

и

UIInterfaceOrientationIsLandscape(orientation)

Ответ 4

-[UIViewController interfaceOrientation]

Однако можно получить устройствоОриентирование, независимо от текущей ориентации интерфейса:

[[UIDevice currentDevice] orientation]

Прочитайте документацию для получения дополнительной информации, но вам нужно сделать еще кое-что, чтобы сделать эту работу.

Ответ 5

Вы также можете проверить внутри функции

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations

    if(interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
    {
       //do for portrait
    }       
    else 
    { 
       //do for Landscape 
    }
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight || 
            interfaceOrientation == UIInterfaceOrientationPortrait || 
            interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
            interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);
}

Ответ 6

Вы должны поместить [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; в свой AppDelegate didFinishLaunchingWithOptions

Затем в любом месте приложения вы можете получить текущую ориентацию с помощью:

UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];

И проверьте ориентацию с помощью:

UIInterfaceOrientationIsPortrait(orientation) UIInterfaceOrientationIsLandscape(orientation)