简体   繁体   English

锁定方向后跟踪设备方向

[英]Track device orientation when orientation is locked

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. 我真正需要的是实现与Instagram相机视图相同的行为:旋转设备时,即使设备锁定,它也会在相机视图上旋转按钮。

I used to track orientation with UIDeviceOrientationDidChangeNotification , but that is not fired when device orientation is locked :( 我曾经使用UIDeviceOrientationDidChangeNotification来跟踪方向,但是当设备方向锁定时,不会触发:(

Is there perhaps implementation somewhere using accelerometer and/or gyroscope? 也许在某处使用加速度计和/或陀螺仪来实现? I'm suprised I couldn't find something like that. 我很惊讶找不到这样的东西。

Use the accelerometer to detect device orientation yourself. 使用加速度计自己检测设备方向。 You can use the Core Motion framework to get the data you need. 您可以使用Core Motion框架来获取所需的数据。 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. 苹果公司有一个名为AccelerometerGraph的示例项目来演示这一点。

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

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