介绍
本示例介绍使用bindContentCover、transition、animateTo实现一镜到底转场动画,常用于首页搜索框点击进入搜索页场景。
效果图预览
使用说明
- 点击首页搜索框跳转到搜索页面显式一镜到底转场动画
实现思路
通过点击首页搜索框改变bindContentCover全屏模态转场中的isSearchPageShow参数控制页面是否显示,同时将modalTransition设置为NONE关闭全屏模态转场的动画,使用transition和animateTo实现首页到搜索页面的转场动画通过bindContentCover全屏模态转场衔接动画。 通过geometryTransition同时绑定首页和搜索页面的search框实现丝滑的上下文传承过渡,达到一镜到底的效果。
- 通过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_borderRadiu