[英]How to get current orientation of device programmatically?
I want to know the device orientation, I used 我想知道我使用的设备方向
UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation
but this only works when I change the orientation otherwise it does not give anything (TRUE/FALSE).So how can I get current device orientation even when orientation is not changed. 但这仅在我改变方向时有效,否则它不会给出任何东西(TRUE / FALSE)。那么即使方向没有改变,我怎样才能获得当前的设备方向。
Thanks in advance! 提前致谢!
To get orientation 获得方向
UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];
and the possible orientations are 并且可能的方向是
typedef enum {
UIInterfaceOrientationPortrait = UIDeviceOrientationPortrait,
UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown,
UIInterfaceOrientationLandscapeLeft = UIDeviceOrientationLandscapeLeft,
UIInterfaceOrientationLandscapeRight = UIDeviceOrientationLandscapeRight
} UIInterfaceOrientation;
UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];
Gives an Implicit Enumeration Warning. 给出隐含的枚举警告。
Use this instead: 请改用:
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
Sorry if you've already done this, but have you looked into the beginGeneratingDeviceOrientationNotifications method, which enables notification generation for the device? 很抱歉,如果您已经这样做了,但是您是否已查看了beginGeneratingDeviceOrientationNotifications方法,该方法可以为设备生成通知?
Also, are you looking for the device orientation or the interface orientation? 此外,您在寻找设备方向还是界面方向? If you're looking for a simpel Portrait vs Landscape orientation info, you should look into the interfaceOrientation of the view controller.
如果您正在寻找一个简单的纵向与横向方向信息,您应该查看视图控制器的interfaceOrientation。
Hope this helps! 希望这可以帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.