HarmonyOS 下拉图片放大效果如何实现

HarmonyOS
2025-01-09 16:38:16
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
shlp

参考示例如下:

// xxx.ets
@Entry
@Component
struct RefreshExample {
  @State isRefreshing: boolean = false
  @State arr: String[] = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
  @State heightNum: number = 0
  @State marginNum: number = 0
  @State imageH: number = 0
  scroller = new Scroller()

  @Builder
  freshArea() {
    Image($r("app.media.startIcon"))
      .width("100%")
      .height(this.heightNum)
      .margin({ top: this.marginNum, bottom: -this.marginNum })
  }

  build() {
    Refresh({ refreshing: $$this.isRefreshing, builder: this.freshArea() }) {
      Scroll(this.scroller) {
        Column() {
          Image($r("app.media.startIcon"))
            .width("100%")
            .onSizeChange((old, newValue) => {
              this.imageH = Number(newValue.height)
              this.marginNum = this.imageH
              this.heightNum = this.imageH
            })
            .opacity(0)
          List({}) {
            ForEach(this.arr, (item: string) => {
              ListItem() {
                Text('' + item)
                  .width('70%')
                  .height(80)
                  .fontSize(16)
                  .margin(10)
                  .textAlign(TextAlign.Center)
                  .borderRadius(10)
                  .backgroundColor(0xFFFFFF)
              }
            }, (item: string) => item)
          }
          .nestedScroll({
            scrollForward: NestedScrollMode.PARENT_FIRST,
            scrollBackward: NestedScrollMode.SELF_FIRST
          })
          .onScrollIndex((first: number) => {
            console.info(first.toString())
          })
          .width('100%')
          .height('100%')
          .alignListItem(ListItemAlign.Center)
          .scrollBar(BarState.Off)
        }
      }
      .onDidScroll((scrollOffset: number) => {
        console.info("进入onDidScroll:", this.scroller.currentOffset().yOffset)
        if (this.scroller.currentOffset().yOffset <= 0) {
          this.marginNum = this.imageH
          return
        }
        // 获取List上滑的高度,控制图片上滑的高度
        let offset =
          this.scroller.currentOffset().yOffset > this.imageH ? this.imageH : this.scroller.currentOffset().yOffset
        this.marginNum = this.imageH - offset;
      })
    }
    .height("100%")
    .onStateChange((refreshStatus: RefreshStatus) => {
      console.info('Refresh onStatueChange state is ' + refreshStatus)
    })
    .onOffsetChange((value: number) => {
      this.heightNum = this.imageH + value
    })
    .onRefreshing(() => {
      setTimeout(() => {
        this.isRefreshing = false
      }, 2000)
      console.log('onRefreshing test')
    })
    .backgroundColor(0x89CFF0)
    .refreshOffset(64)
    .pullToRefresh(false)
  }
}
  • 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.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 82.
  • 83.
  • 84.
  • 85.
  • 86.
  • 87.
  • 88.
分享
微博
QQ
微信
回复
2025-01-09 19:31:26
相关问题
图片模糊效果如何实现
1341浏览 • 1回复 待解决
HarmonyOS 渐变遮罩效果如何实现
761浏览 • 1回复 待解决
文字动画效果如何实现
2568浏览 • 0回复 待解决
渐变动画效果如何实现
89浏览 • 0回复 待解决
HarmonyOS 客户端拖拽效果如何实现
829浏览 • 1回复 待解决
HarmonyOS Webview如何实现下拉刷新效果
545浏览 • 1回复 待解决
不同组件不同样式的效果如何实现
932浏览 • 1回复 待解决
HarmonyOS grid拖拽效果如何添加动画
757浏览 • 1回复 待解决
HarmonyOS 想点击图片放大
475浏览 • 1回复 待解决
HarmonyOS 点击图片放大缩小
652浏览 • 1回复 待解决
HarmonyOS 图片按压效果实现
654浏览 • 2回复 待解决
HarmonyOS 下拉刷新如何实现
354浏览 • 1回复 待解决