1、先在json文件中设置:"pageOrientation": "auto" 开启屏幕可旋转
2、监听横屏 / 竖屏 方法:
onResize:function(res) { var that = this wx.startDeviceMotionListening({ success:function(e){ wx.onDeviceMotionChange(function(resodm){ console.log(resodm) if (resodm.gamma < -40 || resodm.gamma > 40){ that.setData({ isLandscape:true }) //取消监听设备方向变化事件 wx.offDeviceMotionChange() }else{ that.setData({ isLandscape:false }) wx.offDeviceMotionChange() } }) } }) },