Tab动效切换鸿蒙示例代码

鸿蒙场景化示例代码技术工程师
发布于 2025-3-6 17:20
浏览
0收藏

本文原创发布在华为开发者社区

介绍

本项目实现了点击、滑动都可实现Tab切换动效,包含文字切换。

Tab动效切换源码链接

效果预览

Tab动效切换鸿蒙示例代码-鸿蒙开发者社区

使用说明

安装完成后可以通过点击、滑动查看效果。

实现思路

  1. 切换动画开始与结束时触发回调。
.onAnimationStart((index: number, targetIndex: number, event: TabsAnimationEvent) => {
  // 切换动画开始时触发该回调。下划线跟着页面一起滑动,同时宽度渐变。
  this.currentIndex = targetIndex
  let targetIndexInfo = this.getTextInfo(targetIndex)
  this.startAnimateTo(this.animationDuration, targetIndexInfo.left, targetIndexInfo.width)
})
.onAnimationEnd((index: number,event: TabsAnimationEvent) => {
  // 切换动画结束时触发该回调。下划线动画停止。
  let currentIndicatorInfo = this.getCurrentIndicatorInfo(index,event)
  this.startAnimateTo(0,currentIndicatorInfo.left,currentIndicatorInfo.width)
})
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  1. 在页面跟手滑动过程中,逐帧触发该回调。
.onGestureSwipe((index: number,event: TabsAnimationEvent) => {
  let currentIndicatorInfo = this.getCurrentIndicatorInfo(index,event)
  this.currentIndex = currentIndicatorInfo.index
  this.indicatorLeftMargin = currentIndicatorInfo.left
  this.indicatorWidth = currentIndicatorInfo.width
})
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.

分类
已于2025-4-9 15:16:25修改
收藏
回复
举报


回复
    相关推荐