2

キャンバス内でのシングルタッチを防ぐ必要があります。ただし、ダブル/マルチタッチシャウチは、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アプリのキャンバス内でシングルタッチのみを実行したいと思います。ご意見をお聞かせください!

4

1 に答える 1

2

Apple documentation Safari Web Connect Guide Handling Touchesに従って、次のようにイベントからタッチ数を見つけることができます。

    event.touches.length

または、あなたの場合、サンプルコードの関数で:

    e.touches.length

その結果が 1 の場合は、シングルタッチ イベントであり、単純に無視できます。1 でない場合は、マルチタッチ イベントがあり、それを処理するか、デフォルトの処理に渡すことができます。

于 2012-09-18T19:10:03.917 に答える