HarmonyOS 实现按钮长按动画效果

怎么实现一个按钮长按+动画效果

HarmonyOS
2024-12-20 15:30:54
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
Excelsior_abit

类似效果可以参考以下代码

// ets
@Entry
@Component
struct Progress_Ring {
  @State progressValue: number = 0
  @State animationId: number | null = null
  build() {
    Column({ space: 15 }) {
      Stack(){
        Progress({ value: 0, total: 100, type: ProgressType.Ring })
          .color("red")
          .value(this.progressValue)
          .width(120)
          .style({ strokeWidth: 5, scaleCount: 20, scaleWidth: 5, enableSmoothEffect: true })
          .backgroundColor('#00000000')

        Button('test').gesture(
          LongPressGesture({ repeat: true,duration:10 })
            .onAction((event: GestureEvent|undefined) => {
              if(event && this.progressValue<=100){
                clearInterval(this.animationId)
                this.animationId = null
                this.progressValue ++
              }
            })
            .onActionEnd(() => {
              this.animationId = setInterval(()=>{
                this.progressValue --
                if(this.progressValue <=0){
                  clearInterval(this.animationId)
                }
              },10)
            })
        )
      }

    }.width('100%').padding({ top: 5 })
  }
}
  • 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.
分享
微博
QQ
微信
回复
2024-12-20 17:53:45


相关问题
长按实现各类振动效果
1303浏览 • 1回复 待解决
HarmonyOS 动画效果实现
621浏览 • 1回复 待解决
如何实现按钮的点击效果
973浏览 • 2回复 待解决
HarmonyOS clipShape 动画效果实现
167浏览 • 0回复 待解决
如何实现动画转场效果
1363浏览 • 1回复 待解决
属性动画如何实现宽高动画效果
2409浏览 • 1回复 待解决
panGesture结合动画实现fling效果
1288浏览 • 1回复 待解决
文字动画效果如何实现
2244浏览 • 0回复 待解决
在 ArkUl中如何实现动画效果?
361浏览 • 0回复 待解决
如何实现list的折叠动画效果
944浏览 • 1回复 待解决
鸿蒙中怎么实现动画翻转效果
10934浏览 • 2回复 待解决
HarmonyOS List动画效果
498浏览 • 1回复 待解决
HarmonyOS 动画效果+手势
473浏览 • 1回复 待解决
HarmonyOS 列表动画效果
513浏览 • 1回复 待解决