有没有一种特殊的方法来定位iPhone?我不需要它的度数或弧度,我想要它返回一个UIInterfaceOrientation对象.我只是需要它来做一个if-else struct ,比如

if(currentOrientation==UIInterfaceOrientationPortrait ||currentOrientation==UIInterfaceOrientationPortraitUpsideDown) {
//Code
}  
if (currentOrientation==UIInterfaceOrientationLandscapeRight ||currentOrientation==UIInterfaceOrientationLandscapeLeft ) {
//Code
}

提前谢谢!

推荐答案

这很可能就是你想要的:

UIInterfaceOrientation interfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation];

然后可以使用系统宏,如:

if (UIInterfaceOrientationIsPortrait(interfaceOrientation))
{

}

如果需要设备定向,请使用:

UIDeviceOrientation deviceOrientation = [[UIDevice currentDevice] orientation];

这包括像UIDeviceOrientationFaceUpUIDeviceOrientationFaceDown这样的枚举

Objective-c相关问答推荐

覆盖@property setter 和无限循环

应用程序终止时处理推送通知

等到多个网络请求都执行完毕 - 包括它们的完成块

iOS 正确使用 @weakify(self) 和 @strongify(self)

Facebook 的 UIActivityViewController 不显示默认文本

使用 Objective-C 查找 IMEI 号码

dispatch_async(dispatch_get_main_queue(), ^{...});等到完成?

iPhone - 什么是重用标识符(UITableViewCell)?

如何删除手势识别器

从昨天开始无法将存档上传到应用store

以编程方式访问应用标识符前缀

显示启动画面的时间超过默认秒数

-[MyClassName copyWithZone:] 无法识别的 Select 器发送到实例

在 DEBUG 模式下启用和禁用 NSLog

如何在 Objective-C 中添加具有自己的 UIViewController 的子视图?

允许用户从 UILabel 中 Select 文本进行复制

writeToFile:atomically: atomically 是什么意思?

以编程方式设置 UIView 的自动调整大小掩码?

如何让 UITextView 检测网站、邮件和电话号码的链接

如何调整 UITableView 中原型单元格的左边距?