简体   繁体   English

确定状态栏方向

[英]Determining statusbar orientation

I am wanting to detect where the status bar is on my current view in order to determine which segue to perform. 我想检测状态栏在当前视图上的位置,以确定要执行的Segue。 I know the preferred way to do this is to determine the device orientation, but there are two problems with this approach for me: 我知道执行此操作的首选方法是确定设备方向,但是这种方法对我来说有两个问题:

1.) If the device is not angled far enough away from vertical or horizontal then there is no device orientation detected and the segue doesn't happen 1.)如果设备与垂直或水平的角度距离不够远,则说明没有检测到设备方向,也不会发生碰撞

2.) Under certain conditions I am going to "lock" the display orientation such that even though the physical device orientation is landscape the screen is going to be locked to portrait and I will want to perform the portrait segue I have created. 2.)在某些条件下,我将“锁定”显示方向,以便即使物理设备的方向为横向,屏幕也将被锁定为纵向,并且我将要执行我创建的纵向序列。

The problem is that the " [UIApplication sharedApplication].statusBarOrientation = " is not returning the actual orientation of the status bar. 问题是“ [UIApplication sharedApplication] .statusBarOrientation =”没有返回状态栏的实际方向。 Is there not an easy way to detect this? 有没有简便的方法可以检测到这一点? Otherwise I am going to have to write a bunch of messy code to keep track of this. 否则,我将不得不编写一堆凌乱的代码来跟踪此情况。

Have you tried: [[UIDevice currentDevice] orientation] ? 您是否尝试过: [[UIDevice currentDevice] orientation]

Note: 注意:

Depending on the design of your app it might be necessary to call [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications] . 根据您的应用程序的设计,可能需要调用[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications] If you do that, make sure to call [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications] at some point. 如果这样做,请确保在某个时候调用[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications]

If that's not sufficient for your purpose I guess you have to manually check the accelerometer. 如果这还不足以满足您的目的,我想您必须手动检查加速度计。 Take a look at: Handling Motion Events for more info on how that's done. 看一下: 处理运动事件 ,以获取有关如何完成操作的更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM