cjb пре 1 недеља
родитељ
комит
b2cfd75942

+ 61 - 49
entry/src/main/ets/pages/CameraView.ets

@@ -400,7 +400,7 @@ export struct CameraDialog {
     }
     if(this.rotateAngle==90||this.rotateAngle==270)
     {
-      this.scaleValue=0.73
+      this.scaleValue=0.667
     }else {
       this.scaleValue=1
     }
@@ -577,19 +577,19 @@ export struct CameraDialog {
   }
 
   private adjustOffsetWithAnimation() {
-    let moveScale = (this.scaleValue-1)/2
-    // const maxOffsetX =  760*moveScale  //rk3588
-    // const maxOffsetY =  500*moveScale  //rk3588
-    const maxOffsetX =  1524/1.5*moveScale //rk3568
-    const maxOffsetY =  1018/1.5*moveScale  //rk3568
-    // 钳制偏移量到合法范围内
+    const isRotated = (this.rotateAngle === 90 || this.rotateAngle === 270);
+    let moveScaleY = (this.scaleValue - (isRotated ? 0.667 : 1)) / 2;
+    let moveScaleX = (this.scaleValue - (isRotated ? 1.50 : 1)) / 2;
+    let maxOffsetX = (this.scaleValue<1.5&&isRotated) ?this.offsetX: (isRotated ? 506 : 760) * moveScaleX;
+    let maxOffsetY = (isRotated ? 760 : 506) * moveScaleY; //rk3588
+    // let maxOffsetX = (this.scaleValue<1.5&&isRotated) ?this.offsetX: (isRotated ? 1018 : 1524) * moveScaleX;
+    // let maxOffsetY = (isRotated ? 1524 : 1018) * moveScaleY; //rk3568
+    //console.info(TAG,"maxOffsetX",maxOffsetX,"scale",this.scaleValue,"offsetx",this.offsetX)
     const clampedX = Math.max(-maxOffsetX, Math.min(maxOffsetX, this.offsetX));
     const clampedY = Math.max(-maxOffsetY, Math.min(maxOffsetY, this.offsetY));
-
-    // 只有超出边界时才触发动画
     if (this.offsetX !== clampedX || this.offsetY !== clampedY) {
       animateTo({
-        duration: 300,
+        duration: 100,
         curve: Curve.EaseOut
       }, () => {
         this.offsetX = clampedX;
@@ -598,7 +598,6 @@ export struct CameraDialog {
     }
   }
 
-
   //上传照片
   uploadPhoto=()=>{
 
@@ -770,9 +769,9 @@ export struct CameraDialog {
               .width('100%')
               .height('100%')
               .autoResize(true)
-                // .onComplete((event) => {
-                //   console.info(TAG,"width:"+event!.componentWidth +"height:"+ event!.componentHeight)
-                // })  // 获取Image组件的长宽(除以1.5获取vp)
+              // .onComplete((event) => {
+              //   console.info(TAG,"width:"+event!.componentWidth +"height:"+ event!.componentHeight)
+              // })  // 获取Image组件的长宽(除以1.5获取vp)
               .objectFit(ImageFit.Fill)
               .rotate({ angle: this.rotateAngle })
               .scale({ x: this.scaleValue, y: this.scaleValue })
@@ -780,33 +779,24 @@ export struct CameraDialog {
               .translate({ x: this.offsetX, y: this.offsetY })
               .gesture(
                 GestureGroup(GestureMode.Exclusive,
-                  // 替换原有的 PinchGesture 部分代码
                   PinchGesture()
                     .onActionStart((event: GestureEvent) => {
                       this.lastScale = this.scaleValue;
                       this.lastOffsetX = this.offsetX;
                       this.lastOffsetY = this.offsetY;
                       // 记录双指中心点(相对于图片中心)
-                      //this.pinchCenterX = event.pinchCenterX - 1140 / 2;//rk3588
-                      //this.pinchCenterY = event.pinchCenterY - 750 / 2;//rk3588
-
-
-                      this.pinchCenterX = event.pinchCenterX - 1524 / 2; //rk3568
-                      this.pinchCenterY = event.pinchCenterY - 1018 / 2; //rk3568
+                      this.pinchCenterX = event.pinchCenterX - 380 - 760 / 2;//rk3588
+                      this.pinchCenterY = event.pinchCenterY - 130 - 506 / 2;//rk3588
+                      // this.pinchCenterX = event.pinchCenterX - 1016 / 2; //rk3568
+                      // this.pinchCenterY = event.pinchCenterY - 678 / 2; //rk3568
+                     // console.info(TAG,this.pinchCenterX,TAG,this.pinchCenterY)
                     })
                     .onActionUpdate((event: GestureEvent) => {
-                      const newScale = this.lastScale * event.scale;
-                      // 计算缩放中心点相对于图片中心的位置
-                      // const currentCenterX = (event.pinchCenterX - 1140 / 2) - this.lastOffsetX; //rk3588
-                      // const currentCenterY = (event.pinchCenterY - 750 / 2) - this.lastOffsetY;  //rk3588
-
-                      const currentCenterX = (event.pinchCenterX - 1524 / 2) - this.lastOffsetX; //rk3568
-                      const currentCenterY = (event.pinchCenterY - 1018 / 2) - this.lastOffsetY; //rk3568
-
-                      // 计算缩放后的新位置
+                      let newScale = this.lastScale * event.scale;
+                      //保持双指中心点不变
                       const scaleRatio = newScale / this.lastScale;
-                      const newOffsetX = this.lastOffsetX + (currentCenterX * (1 - scaleRatio));
-                      const newOffsetY = this.lastOffsetY + (currentCenterY * (1 - scaleRatio));
+                      const newOffsetX = this.lastOffsetX + (1 - scaleRatio) * this.pinchCenterX;
+                      const newOffsetY = this.lastOffsetY + (1 - scaleRatio) * this.pinchCenterY;
 
                       this.offsetX = newOffsetX;
                       this.offsetY = newOffsetY;
@@ -815,10 +805,10 @@ export struct CameraDialog {
                     .onActionEnd(() => {
                       // 缩放最小比例为1
                       if (this.scaleValue < 1) {
-                        // 旋转90°或者270°的最小缩小比例为0.73
+                        // 旋转90°或者270°的最小缩小比例为0.667
                         if(this.rotateAngle==90||this.rotateAngle==270) {
-                          if(this.scaleValue<0.73){
-                            this.scaleValue = 0.73
+                          if(this.scaleValue<0.667){
+                            this.scaleValue = 0.667
                           }
                         } else {
                           this.scaleValue = 1
@@ -826,23 +816,37 @@ export struct CameraDialog {
                       }
                       // 缩放最大比例为3
                       if (this.scaleValue > 3) this.scaleValue = 3
-                      this.adjustOffsetWithAnimation()
+                     this.adjustOffsetWithAnimation()
                     }),
 
                   // 单指滑动手势
                   PanGesture()
                     .onActionStart(() => {
-                      if (this.scaleValue <= 1) return;
+                      if(this.rotateAngle === 90 || this.rotateAngle === 270)
+                      {
+                        if (this.scaleValue <= 0.667)
+                        {
+                          return;
+                        }
+                      }else{
+                        if (this.scaleValue <= 1) return;
+                      }
                       this.lastOffsetX = this.offsetX;
                       this.lastOffsetY = this.offsetY;
                     })
                     .onActionUpdate((event: GestureEvent) => {
-                      if (this.scaleValue <= 1) return;
-
+                      if(this.rotateAngle === 90 || this.rotateAngle === 270)
+                      {
+                        if (this.scaleValue <= 0.667)
+                        {
+                          return;
+                        }
+                      }else{
+                        if (this.scaleValue <= 1) return;
+                      }
                       let dx = event.offsetX;
                       let dy = event.offsetY;
                       const sensitivity = 0.5 * this.scaleValue;
-
                       // 临时计算新位置
                       let newOffsetX = this.lastOffsetX;
                       let newOffsetY = this.lastOffsetY;
@@ -850,23 +854,31 @@ export struct CameraDialog {
                       newOffsetY += dy * sensitivity;
                       this.offsetX = newOffsetX;
                       this.offsetY = newOffsetY;
+                      //console.info(TAG,this.offsetX,TAG,this.offsetY)
                     })
                     .onActionEnd(() => {
-                      if (this.scaleValue <= 1) {
-                        // 如果缩放比例<=1,直接重置位置
-                        this.offsetX = 0;
-                        this.offsetY = 0;
-                        return;
+                      const isRotated = (this.rotateAngle === 90 || this.rotateAngle === 270);
+                      if(isRotated)
+                      {
+                        if(this.scaleValue<=1.5)
+                        {
+                          this.offsetX = 0
+                        }
+                      }else{
+                        if (this.scaleValue <= 1) {
+                          // 如果缩放比例<=1,直接重置位置
+                          this.offsetX = 0;
+                          this.offsetY = 0;
+                          return;
+                        }
                       }
                       this.adjustOffsetWithAnimation()
-                      // 计算缩
-                      console.info(TAG,this.offsetX,TAG,this.offsetY,TAG,this.scaleValue)
                     })
                 )
               )
           }
-            .width('100%')
-            .height('100%')
+          .width('100%')
+          .height('100%')
           .borderRadius($r('app.float.virtualSize_16'))
           .clip(true)
           Row()

+ 76 - 39
entry/src/main/ets/view/process/MultiMediaCollect.ets

@@ -373,19 +373,18 @@ export struct MultiMediaCollect {
   }
 
   private adjustOffsetWithAnimation() {
-    let moveScale = (this.scaleValue-1)/2
-    // const maxOffsetX =  760*moveScale  //rk3588
-    // const maxOffsetY =  520*moveScale  //rk3588
-    const maxOffsetX =  1635/1.5*moveScale  //rk3568
-    const maxOffsetY =  1038/1.5*moveScale  //rk3568
-    // 钳制偏移量到合法范围内
+    const isRotated = (this.rotateAngle === 90 || this.rotateAngle === 270);
+    let moveScaleY = (this.scaleValue - (isRotated ? 0.667 : 1)) / 2;
+    let moveScaleX = (this.scaleValue - (isRotated ? 1.50 : 1)) / 2;
+    let maxOffsetX = (this.scaleValue<1.5&&isRotated) ?this.offsetX: (isRotated ? 520 : 820) * moveScaleX;
+    let maxOffsetY = (isRotated ? 820 : 520) * moveScaleY;
+    // let maxOffsetX = (this.scaleValue<1.5&&isRotated) ?this.offsetX: (isRotated ? 1038 : 1635) * moveScaleX;
+    // let maxOffsetY = (isRotated ? 1635 : 1038) * moveScaleY;
     const clampedX = Math.max(-maxOffsetX, Math.min(maxOffsetX, this.offsetX));
     const clampedY = Math.max(-maxOffsetY, Math.min(maxOffsetY, this.offsetY));
-
-    // 只有超出边界时才触发动画
     if (this.offsetX !== clampedX || this.offsetY !== clampedY) {
       animateTo({
-        duration: 300,
+        duration: 100,
         curve: Curve.EaseOut
       }, () => {
         this.offsetX = clampedX;
@@ -394,6 +393,28 @@ export struct MultiMediaCollect {
     }
   }
 
+  // private adjustOffsetWithAnimation() {
+  //   let moveScale = (this.scaleValue-1)/2
+  //   // const maxOffsetX =  760*moveScale  //rk3588
+  //   // const maxOffsetY =  520*moveScale  //rk3588
+  //   const maxOffsetX =  1635/1.5*moveScale  //rk3568
+  //   const maxOffsetY =  1038/1.5*moveScale  //rk3568
+  //   // 钳制偏移量到合法范围内
+  //   const clampedX = Math.max(-maxOffsetX, Math.min(maxOffsetX, this.offsetX));
+  //   const clampedY = Math.max(-maxOffsetY, Math.min(maxOffsetY, this.offsetY));
+  //
+  //   // 只有超出边界时才触发动画
+  //   if (this.offsetX !== clampedX || this.offsetY !== clampedY) {
+  //     animateTo({
+  //       duration: 300,
+  //       curve: Curve.EaseOut
+  //     }, () => {
+  //       this.offsetX = clampedX;
+  //       this.offsetY = clampedY;
+  //     });
+  //   }
+  // }
+
   async aboutToAppear() {
     this.loadPhotos();
     await this.createSubscriber();
@@ -577,7 +598,7 @@ export struct MultiMediaCollect {
               .height('100%')
               // .onComplete((event) => {
               //   console.info(TAG,"width:"+event!.componentWidth +"height:"+ event!.componentHeight)
-                // })  // 获取Image组件的长宽(除以1.5获取vp)
+              //   })  // 获取Image组件的长宽(除以1.5获取vp)
               .objectFit(ImageFit.Fill)
               .rotate({ angle: this.rotateAngle })
               .scale({ x: this.scaleValue, y: this.scaleValue })
@@ -592,25 +613,19 @@ export struct MultiMediaCollect {
                       this.lastOffsetX = this.offsetX;
                       this.lastOffsetY = this.offsetY;
                       // 记录双指中心点(相对于图片中心)
-                      // this.pinchCenterX = event.pinchCenterX - 1230 / 2;  //rk3588
-                      // this.pinchCenterY = event.pinchCenterY - 780 / 2;   //rk3588
-
-                      this.pinchCenterX = event.pinchCenterX - 1635 / 2;     //rk3568
-                      this.pinchCenterY = event.pinchCenterY - 1038 / 2;     //rk3568
+                      this.pinchCenterX = event.pinchCenterX - 285 - 820 / 2;  //rk3588
+                      this.pinchCenterY = event.pinchCenterY - 121 - 520 / 2;   //rk3588
+                      // this.pinchCenterX = event.pinchCenterX - 1090 / 2;     //rk3568
+                      // this.pinchCenterY = event.pinchCenterY - 692 / 2;     //rk3568
+                      console.info(TAG,event.pinchCenterX,TAG,event.pinchCenterY)
+                      console.info(TAG,this.pinchCenterX,TAG,this.pinchCenterY)
                     })
                     .onActionUpdate((event: GestureEvent) => {
                       const newScale = this.lastScale * event.scale;
-                      // 计算缩放中心点相对于图片中心的位置
-                      // const currentCenterX = (event.pinchCenterX - 1230 / 2) - this.lastOffsetX; //rk3588
-                      // const currentCenterY = (event.pinchCenterY - 780 / 2) - this.lastOffsetY;  //rk3588
-
-                      const currentCenterX = (event.pinchCenterX - 1635 / 2) - this.lastOffsetX;    //rk3568
-                      const currentCenterY = (event.pinchCenterY - 1038 / 2) - this.lastOffsetY;    //rk3568
-
-                      // 计算缩放后的新位置
+                      //保持双指中心点不变
                       const scaleRatio = newScale / this.lastScale;
-                      const newOffsetX = this.lastOffsetX + (currentCenterX * (1 - scaleRatio));
-                      const newOffsetY = this.lastOffsetY + (currentCenterY * (1 - scaleRatio));
+                      const newOffsetX = this.lastOffsetX + (1 - scaleRatio) * this.pinchCenterX;
+                      const newOffsetY = this.lastOffsetY + (1 - scaleRatio) * this.pinchCenterY;
 
                       this.offsetX = newOffsetX;
                       this.offsetY = newOffsetY;
@@ -619,10 +634,10 @@ export struct MultiMediaCollect {
                     .onActionEnd(() => {
                       // 缩放最小比例为1
                       if (this.scaleValue < 1) {
-                        // 旋转90°或者270°的最小缩小比例为0.73
+                        // 旋转90°或者270°的最小缩小比例为0.667
                         if(this.rotateAngle==90||this.rotateAngle==270) {
-                          if(this.scaleValue<0.73){
-                            this.scaleValue = 0.73
+                          if(this.scaleValue<0.667){
+                            this.scaleValue = 0.667
                           }
                         } else {
                           this.scaleValue = 1
@@ -636,17 +651,31 @@ export struct MultiMediaCollect {
                   // 单指滑动手势
                   PanGesture()
                     .onActionStart(() => {
-                      if (this.scaleValue <= 1) return;
+                      if(this.rotateAngle === 90 || this.rotateAngle === 270)
+                      {
+                        if (this.scaleValue <= 0.667)
+                        {
+                          return;
+                        }
+                      }else{
+                        if (this.scaleValue <= 1) return;
+                      }
                       this.lastOffsetX = this.offsetX;
                       this.lastOffsetY = this.offsetY;
                     })
                     .onActionUpdate((event: GestureEvent) => {
-                      if (this.scaleValue <= 1) return;
-
+                      if(this.rotateAngle === 90 || this.rotateAngle === 270)
+                      {
+                        if (this.scaleValue <= 0.667)
+                        {
+                          return;
+                        }
+                      }else{
+                        if (this.scaleValue <= 1) return;
+                      }
                       let dx = event.offsetX;
                       let dy = event.offsetY;
                       const sensitivity = 0.5 * this.scaleValue;
-
                       // 临时计算新位置
                       let newOffsetX = this.lastOffsetX;
                       let newOffsetY = this.lastOffsetY;
@@ -654,17 +683,25 @@ export struct MultiMediaCollect {
                       newOffsetY += dy * sensitivity;
                       this.offsetX = newOffsetX;
                       this.offsetY = newOffsetY;
+                      //console.info(TAG,this.offsetX,TAG,this.offsetY)
                     })
                     .onActionEnd(() => {
-                      if (this.scaleValue <= 1) {
-                        // 如果缩放比例<=1,直接重置位置
-                        this.offsetX = 0;
-                        this.offsetY = 0;
-                        return;
+                      const isRotated = (this.rotateAngle === 90 || this.rotateAngle === 270);
+                      if(isRotated)
+                      {
+                        if(this.scaleValue<=1.5)
+                        {
+                          this.offsetX = 0
+                        }
+                      }else{
+                        if (this.scaleValue <= 1) {
+                          // 如果缩放比例<=1,直接重置位置
+                          this.offsetX = 0;
+                          this.offsetY = 0;
+                          return;
+                        }
                       }
                       this.adjustOffsetWithAnimation()
-                      // 计算缩
-                      console.info(TAG,this.offsetX,TAG,this.offsetY,TAG,this.scaleValue)
                     })
                 )
               )