I need to prevent single touch inside the canvas. But double/multi touch shouch should perform without issue for IOS application
Please find my JS code for touch event
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;
}
From the above code both single touch and multi touch has been perform but I want to do only single touch inside my canvas for IOS app.
Please advice!
per apple documentation Safari Web Connect Guide Handling Touches, you can find the number of touches from the event thus:
or, in your case, in the functions of your sample code:
if the result of that is 1, you have a single-touch event, and you can simply ignore it. if it is not 1, you have a multi-touch event, and you can process it or pass it on for default handling.