
本示例提供了大头针选择位置并显示弹窗组件的解决方案。该大头针组件分为三个状态,分别是静止态(地图移动过程中,大头针无动画)、加载态(地图停止移动,等待获取地址信息,大头针展示波纹动画表示数据加载中)、显示态(数据加载完成,弹窗显示地址相关信息)。开发者可根据需要直接引入该组件,根据具体使用场景,传入不同的数据,组件根据传入数据的情况显示不同的状态。由于使用场景中,大头针动画需要随时停止,因此选用@ohos.animator实现大头针的波纹和跳动动画。

使用说明
该大头针选择位置并显示弹窗组件入参详细说明如下:
RelativeContainer() {
Column()
...
.zIndex(0)
.alignRules({
bottom: { anchor: '__container__', align: VerticalAlign.Bottom },
middle: { anchor: '__container__', align: HorizontalAlign.Center }
})
.id('invisiblePost')
Column()
...
.alignRules({
bottom: { anchor: 'invisiblePost', align: VerticalAlign.Top },
middle: { anchor: 'invisiblePost', align: HorizontalAlign.Center }
})
.id('tackPost')
Button()
...
.alignRules({
center: { anchor: 'tackPost', align: VerticalAlign.Top },
middle: { anchor: 'tackPost', align: HorizontalAlign.Center }
})
if ((this.thumbTackState === ThumbTackState.LOADING)) {
Button()
...
.id('little1Circle')
.zIndex(this.whiteHatZIdx)
.alignRules({
center: { anchor: 'tackPost', align: VerticalAlign.Top },
middle: { anchor: 'tackPost', align: HorizontalAlign.Center }
})
}
}欢迎大家关注公众号<程序猿百晓生>,可以了解到一下知识点。1.OpenHarmony开发基础
2.OpenHarmony北向开发环境搭建
3.鸿蒙南向开发环境的搭建
4.鸿蒙生态应用开发白皮书V2.0 & V3.0
5.鸿蒙开发面试真题(含参考答案)
6.TypeScript入门学习手册
7.OpenHarmony 经典面试题(含参考答案)
8.OpenHarmony设备开发入门【最新版】
9.沉浸式剖析OpenHarmony源代码
10.系统定制指南
11.【OpenHarmony】Uboot 驱动加载流程
12.OpenHarmony构建系统--GN与子系统、部件、模块详解
13.ohos开机init启动流程
14.鸿蒙版性能优化指南
....... // 跳动动画
createVerticalPostAnimation() {
this.postOffsetAnimator = animator.create({
// 100, 大头针针尖位置偏移动画持续时间100ms
duration: 100,
easing: 'fast-out-slow-in',
// 200, 动画延时200ms执行
delay: 200,
fill: 'forwards',
direction: 'alternate',
iterations: 2,
begin: 0,
end: this.thumbTackWidth * ThumbTackCommonConstants.TACK_POST_ANIMATION_OFFSET_RATIO
})
...
this.postOffsetAnimator.onFrame = (value) => {
this.tackPostOffset = value;
}
this.postHeightAnimator = animator.create({
// 大头针针柄长度动画持续200ms
duration: 200,
easing: 'fast-out-slow-in',
delay: 0,
fill: 'forwards',
direction: 'alternate',
iterations: 2,
begin: this.thumbTackWidth * ThumbTackCommonConstants.TACK_POST_HEIGHT_RATIO,
end: this.thumbTackWidth * ThumbTackCommonConstants.TACK_POST_ANIMATION_HEIGHT_RATIO
})
...
this.postHeightAnimator.onFrame = (value) => {
this.tackPostHeight = value;
}
} // this.pathCmd = 'M0 0 C' + vp2px(2.5) + ' ' + vp2px(0) + ' ' + vp2px(5.6) + ' ' + vp2px(2.4) + ' '
// + vp2px(6.2) + ' ' + vp2px(4.9) + ' L' + vp2px(10) + ' ' + vp2px(20) + ' L0 ' + vp2px(20) + 'Z';
Path({
width: AddressPopupCommonConstants.TIP_AREA_HEIGHT,
height: AddressPopupCommonConstants.TIP_AREA_HEIGHT,
commands: this.pathCmd
})
.fill(this.addressTipBackgroundColor)
.strokeOpacity(0)无
mapthumbtack // har类型
|---src/main/ets/components
| |---LocationAndPopupComponent.ets // 视图层-大头针选择位置并显示弹窗组件
| |---AddressPopUpComponent.ets // 视图层-依赖的地址显示组件
| |---ThumbTackComponent.ets // 视图层-依赖的大头针组件
|---src/main/ets/model
| |---CommonConstants.ets // 模型层-通用常量 如果你觉得这篇内容对你还蛮有帮助,我想邀请你帮我三个小忙:
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。