iphone - UI设备方向

标签 iphone cocoa-touch ios-simulator

我的方法中有以下代码。当我在模拟器中运行它时,调试器会直接跳过代码?我错过了什么?

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/

相关文章:

ios - 为什么不在缓存目录中创建临时目录?

iOS 模拟器看起来模糊且像素化

iOS FBLoginView : the user is not allowed to see this application per the developer set configuration

ios - 当一个改变用户位置而第二个应该保持不变时,如何计算位置之间的距离?

iphone - 验证 iphone 是否已连接到基座

ios - 内容繁重的 iPhone 应用程序的数据格式 - Plist 还是 XML?

ios - 我在哪里可以找到用于启动 xamarin IOS 应用程序的 iphone 模拟器

iphone - iOS:只绘制 UImage 的一部分

ios - 检查 UILabel 中的截断 - iOS、Swift

objective-c - 未调用 Objective C 自定义类方法