1***@qq.com
1***@qq.com
  • 发布:2023-09-09 13:48
  • 更新:2023-10-20 20:17
  • 阅读:129

为什么双指操作后touchend不会触发

分类:uni-app

单指点击屏幕(或者划动),手指移开后会触发touchend,两根手指同时点击屏幕(或者划动)后移开,不会触发touchend,导致无法cancelAnimationFrame,这是什么问题?

  • template部分:

    <view id="container"  
    @touchmove.native.stop="touchmove"  
    @touchstart="touchstart"  
    @touchend="touchend"  
    @touchcancel.native.stop="touchcancel"  
    style="width: 100%; height: 100%"  
    >  
    <canvas type="2d" @touchend="touchend" id="test" @click="click" style="width: 100%; height: 100%; " canvas-id="test"></canvas>  
    </view>
  • script部分:

    export default {  
    props: {  
    // ...省略  
    },  
    data() {  
    return {  
      // ...省略  
      canvas: null,  
      animationFrameId: null  
    }  
    },  
    onReady() {  
    wx.createSelectorQuery().in(this).select('#test')  
      .fields({ node: true, size: true })  
      .exec(res => {  
        const canvas = res[0].node  
        // Canvas 绘制上下文  
        this.canvas = canvas  
        // ...省略  
      })  
    },  
    methods: {  
    touchstart(e) {  
      if (e.touches.length === 2) {  
        // 双指操作  
      } else {  
        // 单指操作  
      }  
      // ...省略  
      this.animationFrameId = this.canvas.requestAnimationFrame(this.startAnimation)  
    },  
    touchmove(e) {  
      if (e.touches.length === 2) {  
        // 双指操作  
      } else {  
        // 单指操作  
      }  
      // ...省略  
    },  
    touchend() {  
      // 双指操作的时候不会触发touchend  
      console.log('end')  
      this.canvas.cancelAnimationFrame(this.animationFrameId)  
    },  
    startAnimation() {  
      // ...省略  
      this.animationFrameId = this.canvas.requestAnimationFrame(this.startAnimation)  
    }  
    }  
    }
2023-09-09 13:48 负责人:无 分享
已邀请:
a***@sina.com

a***@sina.com

同问此问题,9月份之前是可以的。9月份之后就不行了。是不是官方更新了@官

  • 1***@qq.com (作者)

    确实开发体验不太好,不如纯html,总之最后我是换了解决方案,不过如果是app或者H5的话,类似的操作用renderjs应该会好些,接近原生html的开发体验

    2023-12-14 16:52

d***@163.com

要回复问题请先登录注册