问题描述
我的应用程序的一个屏幕是地图。我想允许此屏幕(且仅此屏幕)在用户移动电话并具有横向格式时旋转。
首先,我使用了2个按钮:一个用于将视图锁定为纵向模式,另一个用于锁定为横向模式。但是实际上,如果我允许检测手机的移动以使风景为人像或人像,那会更好。
我想使用这个https://github.com/moshfeu/expo-detect-orientation-device-motion/blob/master/App.js,但是根本没有用。
我想我应该在Expo:ScreenOrientation.OrientationChangeListener中使用它,但是我对如何在代码中使用它有些迷惑,所以如果有人可以给我任何帮助,将不胜感激。非常感谢
这是我的代码:到目前为止,该页面以横向显示,当我更改屏幕时,componentWillUmount无法正常工作,该应用仍以横向显示。我希望该应用能够检测到该特定屏幕上的运动。
this.state = {
orientation:'',...}
componentDidMount
ScreenOrientation.addOrientationChangeListener
ScreenOrientation.lockAsync(ScreenOrientation.OrientationLock.LANDSCAPE);
DeviceMotion.addListener(({rotation}) => {
const alpha = Math.abs(rotation.alpha);
this.setState({
rotation: (alpha > 3 || (alpha > 0 && alpha < 0.5) ? 'LANDSCAPE' : 'PORTRAIT')
});
});
componentWillUnmount() {
ScreenOrientation.lockAsync(ScreenOrientation.Orientation.PORTRAIT);
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)