iphone - 当前设备的 UIInterfaceOrientation 不工作

标签 iphone ios orientation

我想知道我设备的当前方向。

if([[UIDevice currentDevice] orientation] == UIInterfaceOrientationPortrait)
    {

    }

但这行不通

最佳答案

您应该像这样启用设备方向通知:

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]

然后可以查询当前方向

编辑:

来自文档:“除非通过调用 beginGeneratingDeviceOrientationNotifications 启用方向通知,否则此属性的值始终返回 0”(其中 0 是 UIDeviceOrientationUnknown)

关于iphone - 当前设备的 UIInterfaceOrientation 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10715266/

相关文章:

ios - UICollectionView 在更改布局时显示旧单元格

iphone - 录制的音频文件

iPhone UIWebview 在模拟器上加载,但不在设备上加载

iphone - 解除分配当前/上一个 View Controller

iphone - 如何使用特定名称保存 UIImagePicker 图像

ios - Doxygen/headerdoc 是否支持 swift 4.0?

ios - iPod Touch 上的屏幕视频?

android - 屏幕方向更改后继续 Activity - Android

ios - 方向似乎与尺寸冲突

ios - iPad 显示为纵向,但认为它是横向