Возможный дубликат:
ориентация iPhone
Как проверить ориентацию устройства в любой момент времени программно в iPhone?
Спасибо.
Возможный дубликат:
ориентация iPhone
Как проверить ориентацию устройства в любой момент времени программно в iPhone?
Спасибо.
Вот макросы UIDeviceOrientationIsLandscape
и UIDeviceOrientationIsPortrait
поэтому достаточно проверить отдельно, вы можете сделать это вот так...
if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation))
{
// code for landscape orientation
}
ИЛИ
if (UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation))
{
// code for Portrait orientation
}
Попробуйте.
[[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
}
Попробуйте также:
UIInterfaceOrientationIsPortrait(orientation)
и
UIInterfaceOrientationIsLandscape(orientation)
-[UIViewController interfaceOrientation]
Однако можно получить устройствоОриентирование, независимо от текущей ориентации интерфейса:
[[UIDevice currentDevice] orientation]
Прочитайте документацию для получения дополнительной информации, но вам нужно сделать еще кое-что, чтобы сделать эту работу.
Вы также можете проверить внутри функции
- (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);
}
Вы должны поместить [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
в свой AppDelegate didFinishLaunchingWithOptions
Затем в любом месте приложения вы можете получить текущую ориентацию с помощью:
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
И проверьте ориентацию с помощью:
UIInterfaceOrientationIsPortrait(orientation)
UIInterfaceOrientationIsLandscape(orientation)