HarmonyOS NEXT应用开发之搜索页一镜到底案例

734 篇文章 5 订阅
606 篇文章 10 订阅
本文介绍了如何在鸿蒙HarmonyOS中使用bindContentCover、transition和animateTo等技术实现从首页搜索框点击到搜索页的一镜到底转场动画,包括控制页面显示、动画效果和组件间无缝过渡。同时提到了相关组件如SearchComponent的用法和开发资源链接。
摘要由CSDN通过智能技术生成

介绍

本示例介绍使用bindContentCover、transition、animateTo实现一镜到底转场动画,常用于首页搜索框点击进入搜索页场景。

效果图预览

使用说明

  1. 点击首页搜索框跳转到搜索页面显式一镜到底转场动画

实现思路

通过点击首页搜索框改变bindContentCover全屏模态转场中的isSearchPageShow参数控制页面是否显示,同时将modalTransition设置为NONE关闭全屏模态转场的动画,使用transition和animateTo实现首页到搜索页面的转场动画通过bindContentCover全屏模态转场衔接动画。 通过geometryTransition同时绑定首页和搜索页面的search框实现丝滑的上下文传承过渡,达到一镜到底的效果。

  1. 通过bindContentCover全屏模态转场实现对搜索页面显示的控制。源码参考SearchComponent.ets
    Column() {
      Column() {
        Search({ placeholder: $r('app.string.search_placeholder') })
          .focusOnTouch(false)
          .focusable(false)
          .enableKeyboardOnFocus(false)
          .backgroundColor('#E7E9E8')
          .width(this.searchWidth)
          .height(40)
          .borderRadius($r('app.string.main_page_top_borderRadius'))
          .onClick(() => {
            this.onSearchClicked()
          })
          .geometryTransition(this.geometryId, { follow: true })
          // 搜索框转场过渡动画,cubicBezierCurve为三阶贝塞尔曲线动画
          .transition(TransitionEffect.OPACITY.animation({
            duration: 200,
            curve: curves.cubicBezierCurve(0.33, 0, 0.67, 1)
          }))
      }
      .alignItems(HorizontalAlign.Start)
      .backgroundColor('#E7E9E8')
      .borderRadius($r('app.string.main_page_top_borderRadius'))
    }
    .position({ x: this.XPosition })
    // TODO:知识点:通过bindContentCover属性为组件绑定全屏模态页面,在组件插入和删除时可通过设置转场参数ModalTransition显示过渡动效
    .bindContentCover(this.isSearchPageShow, this.SearchPage(), {
      modalTransition: ModalTransition.NONE,
      onDisappear: () => {
        this.onArrowClicked()
      }
    })
    .alignItems(HorizontalAlign.Start)
    .padding({ left: $r('app.string.main_page_padding'), right: $r('app.string.main_page_padding'), top: 48,bottom: 40})
  }

2.通过geometryTransition同时绑定首页和搜索页面的search框实现丝滑的上下文传承过渡,使得原本独立的transition动画在空间位置上发生联系,将视觉焦点由旧视图位置引导到新视图位置。源码参考SearchComponent.ets

Column() {
  Search({ placeholder: $r('app.string.search_placeholder') })
    .focusOnTouch(false)
    .focusable(false)
    .enableKeyboardOnFocus(false)
    .backgroundColor('#E7E9E8')
    .width(this.searchWidth)
    .height(40)
    .borderRadius($r('app.string.main_page_top_borderRadius'))
    .onClick(() => {
       this.onSearchClicked()
    })
    .geometryTransition(this.geometryId, { follow: true })
    // 搜索框转场过渡动画,cubicBezierCurve为三阶贝塞尔曲线动画
    .transition(TransitionEffect.OPACITY.animation({
       duration: 200,
       curve: curves.cubicBezierCurve(0.33, 0, 0.67, 1)
    }))
  }

3.通过transition组件内转场实现搜索页面消失显示过程中的过渡效果。源码参考SearchComponent.ets

    Image($r('app.media.ic_public_back'))
      .width(20)
      .onClick(() => {
         this.onArrowClicked()
      })
      // TODO:知识点:通过transition属性配置转场参数,在组件插入和删除时显示过渡动效。非对称对称转场,第一个为出现动效有150的延迟,第二个为消失动效
      .transition(TransitionEffect.asymmetric(
        TransitionEffect.opacity(0)
          .animation({ curve: curves.cubicBezierCurve(0.33, 0, 0.67, 1), duration: 200, delay: 150 }),
        TransitionEffect.opacity(0)
          .animation({ curve: curves.cubicBezierCurve(0.33, 0, 0.67, 1), duration: 200 }),
      ))

4.在切换过程中使用animateTo显式动画配合改变搜索框大小实现转换过程中的动画和一镜到底的效果。源码参考SearchComponent.ets

  private onSearchClicked(): void {
    this.geometryId = 'search';
    animateTo({
      duration: 100,
      // 构造插值器弹簧曲线对象,生成一条从0到1的动画曲线
      curve: curves.interpolatingSpring(0, 1, 324, 38),
      onFinish: () => {
        this.geometryId = ''
      }
    }, () => {
      this.searchWidth = 400;
      this.isSearchPageShow = true;
    })
  }

高性能知识点

不涉及

工程结构&模块类型

SearchComponent                                 // har类型(默认使用har类型,如果使用hsp类型请说明原因)
|---model
|   |---ListData.ets                            // 筛选数据模型
|---SearchComponent.ets                         // 搜索模块

模块依赖

本场景依赖了路由模块注册路由

参考资料

1.transition详细用法可参考文档

2.animateTo详细用法可参考文档

3.bindContentCover详细用法可参考文档

4.geometryTransition详细用法可参考文档

为了能让大家更好的学习鸿蒙(HarmonyOS NEXT)开发技术,这边特意整理了《鸿蒙开发学习手册》(共计890页),希望对大家有所帮助:[https://qr21.cn/FV7h05](https://qr21.cn/FV7h0
5)

《鸿蒙开发学习手册》:

如何快速入门:https://qr21.cn/FV7h05

  1. 基本概念
  2. 构建第一个ArkTS应用
  3. ……

开发基础知识:https://qr21.cn/FV7h05

  1. 应用基础知识
  2. 配置文件
  3. 应用数据管理
  4. 应用安全管理
  5. 应用隐私保护
  6. 三方应用调用管控机制
  7. 资源分类与访问
  8. 学习ArkTS语言
  9. ……

基于ArkTS 开发:https://qr21.cn/FV7h05

  1. Ability开发
  2. UI开发
  3. 公共事件与通知
  4. 窗口管理
  5. 媒体
  6. 安全
  7. 网络与链接
  8. 电话服务
  9. 数据管理
  10. 后台任务(Background Task)管理
  11. 设备管理
  12. 设备使用信息统计
  13. DFX
  14. 国际化开发
  15. 折叠屏系列
  16. ……

鸿蒙开发面试真题(含参考答案):https://qr18.cn/F781PH

鸿蒙开发面试大盘集篇(共计319页):https://qr18.cn/F781PH

1.项目开发必备面试题
2.性能优化方向
3.架构方向
4.鸿蒙开发系统底层方向
5.鸿蒙音视频开发方向
6.鸿蒙车载开发方向
7.鸿蒙南向开发方向

腾讯T10级高工技术,安卓全套VIP课程全网免费送:https://qr21.cn/D2k9D5

  • 14
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值