HarmonyOS 组件旋转后,平移的x y轴也跟着变了

给图片组件添加缩放,旋转,平移手势。组件旋转180°后,往上滑动,组件会往下面平移。

HarmonyOS
2024-12-24 15:51:16
1.5w浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
FengTianYa

应该是组合手势和rotate冲突,可以在image外面套一层父组件参考下面demo:

build() {
  Column() {
    Text('标题栏')
      .width('100%')
      .height(50)
      .textAlign(TextAlign.Center)
    Column(){
      Image($r('app.media.img'))
        .width(200)
        .height(200)
        .scale({ x: this.scaleValue, y: this.scaleValue, z: 1 })
        .translate({ x: this.offsetX, y: this.offsetY, z: 0 })
        .rotate({
          angle: this.angle,
        })
    }.gesture(GestureGroup(GestureMode.Parallel,
      PanGesture()
        .onActionUpdate((event: GestureEvent) => {
          if (event) {
            this.offsetX = this.positionX + event.offsetX
            this.offsetY = this.positionY + event.offsetY
          }
        })
        .onActionEnd(() => {
          this.positionX = this.offsetX
          this.positionY = this.offsetY
          console.info('Pan end')
        }),
      RotationGesture()
        .onActionUpdate((event: GestureEvent) => {
          if (event) {
            this.angle = this.rotateValue + event.angle
          }
        })
        .onActionEnd((event: GestureEvent) => {
          this.rotateValue = this.angle
          console.info('Rotation end')
        })
    )
    )
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
分享
微博
QQ
微信
回复
2024-12-24 18:25:04
相关问题
HarmonyOS 如何实现Y旋转
688浏览 • 1回复 待解决
HarmonyOS 组件旋转平移方向出错
589浏览 • 1回复 待解决
HarmonyOS如何获取inputTextXY
939浏览 • 1回复 待解决
HarmonyOS 组件旋转
643浏览 • 1回复 待解决
HarmonyOS 平移动画
699浏览 • 1回复 待解决
HarmonyOS 平移动画问题
516浏览 • 1回复 待解决