我的方法中有以下代码。当我在模拟器中运行它时,调试器会直接跳过代码?我错过了什么?
if (([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft) ||
([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight))
{
} else {
}
最佳答案
确定界面方向的最佳方法是查看状态栏方向:
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if(orientation == UIInterfaceOrientationPortrait ||
orientation == UIInterfaceOrientationPortraitUpsideDown) {
//Portrait orientation
}
if(orientation == UIInterfaceOrientationLandscapeRight ||
orientation == UIInterfaceOrientationLandscapeLeft) {
//Landscape orientation
}
UIDevice
类根据加速度计测量方向,如果设备平放,它将不会返回正确的方向。
关于iphone - UI设备方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/930075/