简体   繁体   English

如何检测 iOS 上的 UI 方向是否被锁定?

[英]How can I detect if UI orientation is locked or not on iOS?

Is it possible to detect UI orientation is locked or not currently?是否可以检测到当前 UI 方向是否已锁定? If so, how can I do that?如果是这样,我该怎么做?

I want to do something with gravity sensor when only UI orientation is not locked.当只有 UI 方向未锁定时,我想用重力传感器做一些事情。

Not possible unfortunately, the lock is handled by the OS and is transparent to the app.不幸的是,锁是由操作系统处理的,对应用程序是透明的,这是不可能的。

Why not try calling the shouldAutorotate method and see what BOOL value is returned?为什么不尝试调用 shouldAutorotate 方法并查看返回的 BOOL 值?

I haven't tried looking for the UIOrientation lock.我还没有尝试寻找 UIOrientation 锁。 But off the top of my head, this is how I'd try.但在我的脑海中,这就是我会尝试的方式。

if([self shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationLandscapeLeft])
    NSLog(@"Rotates LandscapeLeft");

if([self shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationLandscapeRight])
    NSLog(@"Rotates LandscapeRight");

if([self shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationPortrait])
    NSLog(@"Rotates Portrait");

if([self shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationPortraitUpsideDown])
    NSLog(@"Rotates PortraitUpsideDown");

Hopefully this solves your problem.希望这可以解决您的问题。

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

相关问题 即使方向被锁定,我如何检测设备方向 - How can i detect device orientation even if the orientation is locked 如何在 iOS 上检测设备的方向? - How Do I detect the orientation of the device on iOS? 如果屏幕在纵向模式下被锁定,如何检测方向? - How to detect orientation, if screen is locked in portrait mode? iOS如何检测方向完成 - IOS how to detect the orientation completed 如何在 iOS 上使用 Phonegap 正确检测方向变化? - How do I correctly detect orientation change using Phonegap on iOS? 尽管锁定了显示方向,如何检测设备旋转? - How to detect device rotation despite locked display orientation? iOS:如何更改UICollectionViewCell的方向? - iOS: How can I change the orientation of a UICollectionViewCell? 当用户锁定屏幕旋转时,我如何以编程方式知道设备方向 - how can i know the device orientation programmatically when user locked screen rotation 锁定iOS设备后,如何启用对NSURLCredentials的访问? - How can I enable access of NSURLCredentials when an iOS Device is locked? 如何检测视图控制器iOS的当前方向? - How to detect current orientation of a view controller iOS?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM