Przeglądaj źródła

触摸事件偏移问题

haojianlong 4 lat temu
rodzic
commit
012f4118bf
1 zmienionych plików z 7 dodań i 3 usunięć
  1. 7 3
      saga-web-draw/src/SCanvasView.ts

+ 7 - 3
saga-web-draw/src/SCanvasView.ts

@@ -312,6 +312,7 @@ export class SCanvasView extends SObject {
     protected onTouchStart(event: TouchEvent): void {
         let touches = event.touches;
         if (touches.length == 1) {
+            this._touchState = STouchState.Move;
             this._touchPoint.x = event.touches[0].clientX;
             this._touchPoint.y = event.touches[0].clientY;
         }
@@ -328,13 +329,13 @@ export class SCanvasView extends SObject {
      */
     protected onTouchMove(event: TouchEvent): void {
         let touches = event.touches;
-        if (touches.length == 1) {
+        if (touches.length == 1 && this._touchState == STouchState.Move) {
             this.origin.x += event.touches[0].clientX - this._touchPoint.x;
             this.origin.y += event.touches[0].clientY - this._touchPoint.y;
             this._touchPoint.x = event.touches[0].clientX;
             this._touchPoint.y = event.touches[0].clientY;
         }
-        if (touches.length == 2) {
+        if (touches.length == 2 && this._touchState == STouchState.Zoom) {
             this.viewZoom(event);
         }
         this.update();
@@ -346,7 +347,10 @@ export class SCanvasView extends SObject {
      * @param   event       事件参数
      */
     protected onTouchEnd(event: TouchEvent): void {
-        this._touchState = STouchState.None;
+        const touches = event.touches.length;
+        if (touches == 0) {
+            this._touchState = STouchState.None;
+        }
     } // Function onTouchEnd()
 
     /**