HarmonyOS 平移动画问题?

代码如下:

@Entry
@Component
struct TranslateAnimatePage {
  @State isPresent: boolean = false;
  private tagList: string[] = ["aaa", "bbb", "ccc", "ddd", "eee", "fff", "ggg", "hhh", "iii"];
  private showFilterHeight: number = 400;
  private duration: number = 1500;

  build() {
    Column() {
      Row()
        .width("100%")
        .height(200)
        .backgroundColor('#ED5151')
        .onClick(() => {
          this.isPresent = !this.isPresent;
        });

      Stack({ alignContent: Alignment.Top }) {
        Row() {
          Text('周三五折即将开始')
            .fontColor('#ED5151')
            .borderColor('#ED5151')
            .height(24)
            .fontSize(12)
            .borderWidth(0.7)
            .padding({ left: 10, right: 10 })
            .borderRadius(4);

          Blank()
            .layoutWeight(1);

          Text('分类')
            .fontColor('#ED5151')
            .height(24)
            .fontSize(12)
            .padding({ left: 10, right: 10 })
            .onClick(() => {
              this.isPresent = !this.isPresent;
            });
        }.padding({ top: 6, left: 15, bottom: 6 })
        .backgroundColor(Color.White);
        if (this.isPresent) {
          Stack({ alignContent: Alignment.Top }) {
            List() {
              ForEach(this.tagList, (item: string) => {
                ListItem() {
                  Text(item)
                    .fontSize(14)
                    .fontColor('#ED5151')
                    .height(36)
                    .width('100%')
                    .textAlign(TextAlign.Center)
                    .borderRadius(14)
                    .padding({ left: 10, right: 10 });
                }
              }, (item: string) => {
                return item;
              })
            }
            .height(this.showFilterHeight)
            .width('100%')
            .backgroundColor('#F5F5F5')
            .borderRadius({ bottomLeft: 8, bottomRight: 8 })
            .transition(TransitionEffect.translate({ y: -this.showFilterHeight })
              .animation({ duration: this.duration }));
          }
          .height('100%')
          .width('100%')
          .backgroundColor("#7F202020")
          .transition(TransitionEffect.opacity(0.5).animation({ duration: this.duration }))
          .margin({
            top: 36
          });
        }
      }
    }.height('100%')
    .width('100%')
    .backgroundColor('#F5F5F5')
  }
}
阅读 574
1 个回答
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进