如何使用Expo / React-Native检测向前和向后倾斜

我目前正在使用expo-sensors库通过检测陀螺仪的y轴值来检测向前和向后倾斜,如下代码所示

subscribeGyro = async () => {
        this.gyroSubscription = Gyroscope.addListener(async (result) => {
            console.log('checking x y z ',result.x,' ',result.y,result.z)
            if(result.y >= 0.5){
                console.log('result ',result.y)
                this.passQuestion()
            }
            else if(result.y <= -0.4){
                console.log('result ',result.y)
                this.answerQuestion()
            }
            this.setState({ gyroscopeData: result });
        })
    }

如果y值> = 5,则表示用户将手机向后倾斜;如果y值

感谢您的帮助。

谢谢。

xuepan2006 回答:如何使用Expo / React-Native检测向前和向后倾斜

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3142796.html

大家都在问