收藏
回答

canvas组件在iphone 15 Pro Max上无法正确绘制

问题类型 API/组件名称 微信版本 基础库版本
Bug canvas 8.0.68 3.14.1
<canvas
    type="2d"
    class="canvas"
    catch:touchstart="catchtouchstart"
    catch:touchmove="catchtouchmove"
></canvas>
 onReady() {
      this.initCanvas()
  },
 initCanvas() {
      const {
          windowWidth,
          windowHeight,
          pixelRatio: dpr
      } = wx.getSystemInfoSync()

      // 创建 canvas 画布上下文
      wx.createSelectorQuery()
          .select('.canvas')
          .node()
          .exec(res => {
              const canvas = res[0].node
              // 设置画布大小
              canvas.width = windowWidth * dpr
              canvas.height = windowHeight * dpr
              this.data.canvas = canvas
              // 初始化画布
              this.data.ctx = canvas.getContext('2d')
              this.data.ctx.textAlign = 'center'
              this.data.ctx.font = '240px sans-serif'
              this.data.ctx.fillStyle = '#E8EAED'
              this.data.ctx.fillText('签名区', canvas.width / 2, 360)
              this.data.ctx.scale(dpr, dpr)
          })
  },


  catchtouchstart(e) {
      // 判断开始签名
      if (this.data.drawCount === 0) {
          this.handleClear('emit')
      }
      const { clientX, clientY } = e.changedTouches[0]


      this.data.drawCount++
      this.data.ctx.strokeStyle = '#000000'
      this.data.ctx.lineWidth = 6
      this.data.ctx.lineCap = 'round'
      this.data.ctx.lineJoin = 'round'
      this.data.ctx.beginPath()
      this.data.ctx.moveTo(clientX, clientY)
  },

  catchtouchmove(e) {
      // 签名结束则不执行
      if (this.data.drawState === 'stop') return
      // 判断有多点触屏,则不执行
      if (e.touches.length > 1) return
      const { clientX, clientY } = e.changedTouches[0]
      this.data.drawState = 'ing'
      this.data.ctx.lineTo(clientX, clientY)
      this.data.ctx.stroke()
      this.data.ctx.moveTo(clientX, clientY)
  },

会出现这种笔画跟触摸不同频的问题,手指在左边画,笔画出现在右边,而且还会延迟出现,其他机型正常,就15这个不行

回答关注问题邀请回答
收藏

2 个回答

  • 社区技术运营专员--Asher
    社区技术运营专员--Asher
    02-03

    这边测试16正常,换机型试试能不能复现

    02-03
    有用
    回复
  • 智能回答 智能回答 本次回答由AI生成
    02-02
    有用
    回复 1
登录 后发表内容