我有一种情况,我想为不同的方向(纵向和横向)调用单独的方法。
例如:
If (Orientation == Portrait)
{
Some method a;
}
Elseif (Orientation == Landscape)
{
Some method b;
}
我有一种情况,我想为不同的方向(纵向和横向)调用单独的方法。
例如:
If (Orientation == Portrait)
{
Some method a;
}
Elseif (Orientation == Landscape)
{
Some method b;
}
我曾经[[UIApplication sharedApplication] statusBarOrientation]
知道方向。
然后我用这个方法
if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation])) {
//Do something if landscape
} else {
//Do something in portrait
}
不要使用[[UIDevice currentDevice] orientation]
,因为如果设备放在桌子上,它就不能正常工作,例如。
if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation))
{
// code for landscape orientation
}
if (UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation))
{
// code for Portrait orientation
}
UIDeviceOrientationIsLandscape
并且UIDeviceOrientationIsPortrait
是宏的。
UIDeviceOrientation deviceOrientation = [[UIDevice currentDevice] orientation];
if(deviceOrientation == UIDeviceOrientationPortrait)
...
else ...
枚举是UIDeviceOrientation[something]
试试这个:
UIInterfaceOrientation interfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation];
if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight)
{// perform ua operation for landscape mode
} 别的{
//纵向模式执行ua操作 };
目标-c:
-(void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
{
if (UIDevice.currentDevice.orientation == UIInterfaceOrientationPortrait) {
printf("Portrait");
} else {
printf("Landscape");
}
}