9

Is it possible to detect UI orientation is locked or not currently? If so, how can I do that?

I want to do something with gravity sensor when only UI orientation is not locked.

usealbarazer
  • 707
  • 3
  • 10
  • 27
eonil
  • 83,476
  • 81
  • 317
  • 516
  • possible duplicate of [iOS device orientation disregarding orientation lock](http://stackoverflow.com/questions/4574693/ios-device-orientation-disregarding-orientation-lock) – CRABOLO Sep 02 '14 at 07:05

2 Answers2

2

Not possible unfortunately, the lock is handled by the OS and is transparent to the app.

adam
  • 22,404
  • 20
  • 87
  • 119
0

Why not try calling the shouldAutorotate method and see what BOOL value is returned?

I haven't tried looking for the UIOrientation lock. 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.

Nitin Alabur
  • 5,812
  • 1
  • 34
  • 52
  • This doesn't work as shouldAutorotate is not called when the lock is enabled – Yoko Feb 05 '16 at 14:48
  • it "should not" work if the lock is enabled. If you want to know the rotation, then you should be using UIDeviceOrientation. – Nitin Alabur Feb 08 '16 at 15:25