react native 触摸的响应方法以及过程(三)

手势的上下左右判断的方法

moveActionEnd: function (movePos) {
    this.console("movePos" + JSON.stringify(movePos));
    let [sX, sY, eX, eY] = movePos;//开始X坐标 开始Y坐标 结束X坐标 结束Y坐标
    let x = eX - sX, y = eY - sY, direction;
    let z = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));
    if ((eX == 0 && eY == 0) || z < 20) {//移动距离小于20像素视为点击
        direction = -1;
    } else {
        direction = Math.round(( ( ( Math.atan2(y, x) * ( 180 / Math.PI ) ) + 180 ) / 90) + 3) % 4;
    }
    this.console("角度:" + direction);// 点击(-1) 上(0) 右(1) 下(2) 左(3)
    switch (direction) {
        case -1:
            this.keyPressIn(6);
            break;
        case 0:
            this.keyPressIn(2);
            break;
        case 1:
            this.keyPressIn(5);
            break;
        case 2:
            this.keyPressIn(3);
            break;
        case 3:
            this.keyPressIn(4);
            break;
        default :
            break;
    }
}
该示例代码为触摸遥控器解决方案的一部分代码,完整示例代码将会在 react native触摸遥控器解决方案 提供。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值