Explorar el Código

添加touch 相关事件处理

haojianlong hace 5 años
padre
commit
daeb83597c
Se han modificado 2 ficheros con 29 adiciones y 4 borrados
  1. 1 1
      saga-web-draw/package.json
  2. 28 3
      saga-web-draw/src/SCanvasView.ts

+ 1 - 1
saga-web-draw/package.json

@@ -1,6 +1,6 @@
 {
     "name": "@saga-web/draw",
-    "version": "2.1.60",
+    "version": "2.1.71",
     "description": "上格云绘制引擎。",
     "main": "lib/index.js",
     "types": "lib/index.d.js",

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

@@ -74,6 +74,8 @@ export class SCanvasView extends SObject {
 
     /** 手执状态 */
     private _touchState = STouchState.None;
+    /** 手指拖动点 */
+    private _touchPoint = new SPoint();
     /** 未缩放时二指间距离 */
     private _beforeLength = 0;
     /** 缩放后二指间距离 */
@@ -297,21 +299,44 @@ export class SCanvasView extends SObject {
      *
      * @param   event       事件参数
      */
-    protected onTouchStart(event: TouchEvent): void {} // Function onTouchStart()
+    protected onTouchStart(event: TouchEvent): void {
+        let touches = event.touches;
+        if (touches.length == 1) {
+            this._touchPoint.x = event.touches[0].clientX;
+            this._touchPoint.y = event.touches[0].clientY;
+        }
+        if (touches.length == 2) {
+            this._touchState = STouchState.Zoom;
+            this._beforeLength = this.getDistance(event);
+        }
+    } // Function onTouchStart()
 
     /**
      * 触摸移动事件
      *
      * @param   event       事件参数
      */
-    protected onTouchMove(event: TouchEvent): void {} // Function onTouchMove()
+    protected onTouchMove(event: TouchEvent): void {
+        let touches = event.touches;
+        if (touches.length == 1) {
+            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) {
+            this.viewZoom(event);
+        }
+    } // Function onTouchMove()
 
     /**
      * 结束触摸事件
      *
      * @param   event       事件参数
      */
-    protected onTouchEnd(event: TouchEvent): void {} // Function onTouchEnd()
+    protected onTouchEnd(event: TouchEvent): void {
+        this._touchState = STouchState.None;
+    } // Function onTouchEnd()
 
     /**
      * View大小变更事件