我想知道设备的方向,我使用了
UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation
但是这仅在我改变方向时才有效,否则它不会返回任何内容(TRUE / FALSE)。那么如何获取当前设备方向,即使未更改方向。
提前致谢!
UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation
但是这仅在我改变方向时才有效,否则它不会返回任何内容(TRUE / FALSE)。那么如何获取当前设备方向,即使未更改方向。
提前致谢!
获取方向
UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];
可能的方向有:
typedef enum {
UIInterfaceOrientationPortrait = UIDeviceOrientationPortrait,
UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown,
UIInterfaceOrientationLandscapeLeft = UIDeviceOrientationLandscapeLeft,
UIInterfaceOrientationLandscapeRight = UIDeviceOrientationLandscapeRight
} UIInterfaceOrientation;
UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];
警告隐式枚举。
请改用下面的代码:
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
抱歉如果您已经这样做了,但是您是否研究过 beginGeneratingDeviceOrientationNotifications 方法,该方法可以启用设备的通知生成?
另外,您是在寻找设备方向还是界面方向?如果您只是想要一个简单的纵向或横向方向信息,您应该查看视图控制器的interfaceOrientation。
希望这可以帮助您!