[英]Detect actual orientation of the device when the Orientation lock is enabled (iOS)
Disclaimer :This is not a duplicate of any question.I have gone through this question before posting here.免责声明:这不是任何问题的重复。我在这里发帖之前已经解决了这个问题。
Normally we use device orientation property or status bar property to find out the actual orientation of the device.通常我们使用设备方向属性或状态栏属性来找出设备的实际方向。 But i am not getting the correct orientation when orientation lock is enabled on the device.
但是当在设备上启用方向锁定时,我没有得到正确的方向。 I am always getting the orientation value as portrait even though i turn the device into landscape mode.
即使我将设备转换为横向模式,我也总是将方向值设为纵向。
Is there a way to find out the actual orientation of the device when the orientation lock is enabled on the device.在设备上启用方向锁定时,有没有办法找出设备的实际方向。
Note : UIAccelerometer is now deprecated.注意:现在不推荐使用 UIAccelerometer。 Any help with respect to CoreMotion is welcome.
欢迎任何有关 CoreMotion 的帮助。
Here is what I came up with:这是我想出的:
CMMotionManager *cm=[[CMMotionManager alloc] init];
cm.deviceMotionUpdateInterval=0.2f;
[cm startDeviceMotionUpdatesToQueue:[NSOperationQueue mainQueue]
withHandler:^(CMDeviceMotion *data, NSError *error) {
if(fabs(data.gravity.x)>fabs(data.gravity.y)){
NSLog(@"LANSCAPE");
if(data.gravity.x>=0){
NSLog(@"LEFT");
}
else{
NSLog(@"RIGHT");
}
}
else{
if(data.gravity.y>=0){
NSLog(@"DOWN");
}
else{
NSLog(@"UP");
}
}
}];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.