HarmonyOS 鸿蒙Next如何判断设备水平翻转(屏幕朝下)
HarmonyOS 鸿蒙Next如何判断设备水平翻转(屏幕朝下)
尝试通过方向传感器和旋转矢量传感器来判断 但是数值跳动的很乱 不知道该如何界定屏幕朝下的相对值 有大佬开发过屏幕翻转的需求么 麻烦请教一下
try {
sensor.on(sensor.SensorId.ORIENTATION, (data: sensor.OrientationResponse) => {
MpContext.getInstance().secureGetString(‘isFlip’+MpContext.getInstance().sessionGetString(‘userSeq’)).then((res:string) =>{
console.log(‘data.alpha’,data.alpha)
if(MpContext.getInstance().sessionGetString(‘isLogin’) == ‘true’ && data.alpha >= 300 && res == ‘1’) {
// LogoutMethod.getInstance().logout(‘0’)
try {
sensor.on(sensor.SensorId.ROTATION_VECTOR, (data: sensor.RotationVectorResponse) => {
console.info('Succeeded in invoking on. X-coordinate component: ’ + data.x);
console.info('Succeeded in invoking on. Y-coordinate component: ’ + data.y);
console.info('Succeeded in invoking on. Z-coordinate component: ’ + data.z);
console.info('Succeeded in invoking on. Scalar quantity: ’ + data.w);
}, { interval: 700000000 });
} catch (error) {
let e: BusinessError = error as BusinessError;
console.error(Failed to invoke on. Code: ${e.code}, message: ${e.message}
);
}
}else {
sensor.off(sensor.SensorId.ROTATION_VECTOR);
}
})
}, { interval: 700000000 });
} catch (error) {
let e: BusinessError = error as BusinessError;
console.error(Failed to invoke on. Code: ${e.code}, message: ${e.message}
);
}