0

I need to track device orientation even though device orientation is locked to Portrait mode. What I really need is to accomplish similar behaviour to what Instagram camera view has: when you rotate device, it will rotate buttons over camera view, even when your device is locked.

I used to track orientation with UIDeviceOrientationDidChangeNotification, but that is not fired when device orientation is locked :(

Is there perhaps implementation somewhere using accelerometer and/or gyroscope? I'm suprised I couldn't find something like that.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
mixtly87
  • 1,675
  • 15
  • 32
  • 1
    Yes, you will need to use another mechanism. You don't get the notifications because otherwise you would have to put in some code to deal with the orientation change message being received and the display being orientation locked which kinda defeats the purpose of it being a system-level switch – Anya Shenanigans Apr 25 '14 at 13:41

1 Answers1

1

Use the accelerometer to detect device orientation yourself. You can use the Core Motion framework to get the data you need. There's a sample snippet in the linked docs that shows how to get the data. Use a low-pass filter to isolate the force of gravity from relatively short-term changes due to user movement. Apple has a sample project called AccelerometerGraph that demonstrates this.

Community
  • 1
  • 1
Caleb
  • 124,013
  • 19
  • 183
  • 272
  • I understand, but then I would have to do a research on subject and go through implementation/debug process. Does anyone know if there already exist solution to this? – mixtly87 Apr 26 '14 at 15:58
  • @mixtly87 Resource recommendation questions are off topic on SO. – Caleb Apr 27 '14 at 01:52