HarmonyOS 实现展开区域的徐徐展开特效

有个区域是隐藏的,点击按钮会显示这个区域,显示的时候加个特效,一点点从上往下展开

if (this.item.isExpand) {
  Column() {
    显示内容详情区域....
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
HarmonyOS
2024-12-25 07:33:46
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
superinsect

可以试下在点击展开时添加animateTo的改变Column组件高度的方式实现徐徐展开效果,animateTo具体使用可以参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-explicit-animation-V5

@State flag1: boolean = false
@State flag2: boolean = true
@State color: Color = Color.Red;

build() {
  Row() {
    Button('点击')
      .backgroundColor(this.color)
      .onClick(() => {
        if (this.color !== Color.Blue) {
          this.flag1 = true
          // 展开动画
          animateTo({
            duration: 300,
            curve: curves.springMotion(0.5, 0.8),
          }, () => {
            this.color = Color.Blue;
            this.flag2 = false;
          })
        } else {
          // 收起动画
          this.flag1 = false
          animateTo({
            duration: 300,
            curve: Curve.Friction,
          }, () => {
            this.color = Color.Red;
            this.flag2 = true;
          })
        }

      })
    if (this.flag1) {
      Column() {
        Row() {
          Row() {
            Text("文字")
          }
          .backgroundColor(Color.Pink)
          .height(30)
          .borderRadius(15)
          .width(100)
          .justifyContent(FlexAlign.End)
          .padding({ left: 10, right: 10 })
          .animation({ duration: 300 })
        }.justifyContent(FlexAlign.End)
        .width("100%")
      }
      .position({
        x:100,y:0
      })
      .width('50%')
      .height(this.flag2 ? '0%' : '80%')
      .backgroundColor(Color.Gray)
    }
  }
  .height('100%')
}
  • 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.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
分享
微博
QQ
微信
回复
2024-12-25 09:54:42
相关问题
ArkTS实现Text文本【...展开
2534浏览 • 3回复 待解决
HarmonyOS 如何实现半屏展开
1007浏览 • 1回复 待解决
HarmonyOS 如何实现展开listview功能
535浏览 • 1回复 待解决
如何实现文本展开收起功能
1404浏览 • 1回复 待解决
HarmonyOS 如何监听折叠屏展开折叠
886浏览 • 1回复 待解决
HarmonyOS 列表分组可折叠和展开
1089浏览 • 1回复 待解决
HarmonyOS 如何监听折叠/展开状态
784浏览 • 1回复 待解决
HarmonyOS 长按桌面图标展开菜单
479浏览 • 1回复 待解决
HarmonyOS Object不支持 ... 展开符吗?
1240浏览 • 1回复 待解决
多行文本省略展开与显示
1877浏览 • 1回复 待解决