我需要防止画布内部的单点触摸。但是,对于IOS应用程序,双/多点触控应该没有问题
请查找我的触摸事件JS代码
onTouchStart: function(e, win, eventInfo) {
if(!this.config.panning) return;
if(this.config.panning == 'avoid nodes' && (this.dom? this.isLabel(e, win) : eventInfo.getNode())) return;
this.pressed = true;
this.pos = eventInfo.getPos();
var canvas = this.canvas,
ox = canvas.translateOffsetX,
oy = canvas.translateOffsetY,
sx = canvas.scaleOffsetX,
sy = canvas.scaleOffsetY;
this.pos.x *= sx;
this.pos.x += ox;
this.pos.y *= sy;
this.pos.y += oy;
},
onTouchMove: function(e, win, eventInfo) {
if(!this.config.panning) return;
if(!this.pressed) return;
if(this.config.panning == 'avoid nodes' && (this.dom? this.isLabel(e, win) : eventInfo.getNode())) return;
var thispos = this.pos,
currentPos = eventInfo.getPos(),
canvas = this.canvas,
ox = canvas.translateOffsetX,
oy = canvas.translateOffsetY,
sx = canvas.scaleOffsetX,
sy = canvas.scaleOffsetY;
currentPos.x *= sx;
currentPos.y *= sy;
currentPos.x += ox;
currentPos.y += oy;
var x = currentPos.x - thispos.x,
y = currentPos.y - thispos.y;
this.pos = currentPos;
this.canvas.translate(x * 1/sx, y * 1/sy);
},
onTouchEnd: function(e, win, eventInfo) {
if(!this.config.panning) return;
this.pressed = false;
},
onTouchCancel: function(e, win, eventInfo) {
if(!this.config.panning) return;
this.pressed = false;
}从上面的代码中,单点触控和多点触控都已经执行了,但我只想在IOS应用程序的画布中执行单点触控。请多多指教!
发布于 2012-09-19 03:10:04
根据apple documentation Safari Web Connect Guide Handling Touches,您可以找到事件的触摸次数,如下所示:
event.touches.length或者,在您的示例代码的函数中:
e.touches.length如果结果是1,那么你有一个单点触摸事件,你可以直接忽略它。如果它不是1,那么你有一个多点触摸事件,你可以处理它或者将它传递给默认的处理。
https://stackoverflow.com/questions/12404801
复制相似问题