html52.com
我爱小程序-开发者交流社区

关于onTouchEnd中触点changedTouches的坐标游戏

- 需求的场景描述(希望解决的问题)

用代码监听413<posX<440 378<posY<404(机型iphone7  屏幕大小为375X667)   这一片区域(对应一个关闭按钮,有点击这片区域时 清除ctx)   但屏幕大小改变(如换成320X568的iphone5)   按钮对应区域不再是413<posX<440 378<posY<404了


wx.onTouchEnd(event => {

let lastTouchPoint = event.changedTouches[0];

let posX = lastTouchPoint.screenX;

let posY = lastTouchPoint.screenY;

console.log("--------------posX-----------",posX);

console.log("--------------posY-----------",posY);

let leftBoundary=413+(width-375)/2;

let rightBoundary=440+(width-375)/2;

let topBoundary=378+(height-667);

let bottomBoundary=404+(height-667);


if (posX <= rightBoundary && posX >= leftBoundary && posY >= topBoundary && posY <= bottomBoundary) {

ctx.clearRect(0, 0, sharedCanvas.width, sharedCanvas.height);

wx.offTouchEnd();

}

})



- 希望提供的能力

  试过用比例算法将范围定为413*(width/375) 等   但触点的ScreenX 与ScreenY并不与比例对应   求解触点与屏幕大小的适应关系

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

真正的个人免签约支付接口

云免签H5支付