当前位置: 首页 > news >正文

朝阳周边网站建设北京网络营销外包公司哪家好

朝阳周边网站建设,北京网络营销外包公司哪家好,网络营销策划书实施计划,怎么做微信电影网站【引言】 在鸿蒙NEXT应用开发中,实现图片切换动画是一项常见的需求。本文将介绍如何使用鸿蒙应用框架中的组件和动画功能,实现不同类型的图片切换动画效果。 【环境准备】 电脑系统:windows 10 开发工具:DevEco Studio NEXT B…

【引言】

在鸿蒙NEXT应用开发中,实现图片切换动画是一项常见的需求。本文将介绍如何使用鸿蒙应用框架中的组件和动画功能,实现不同类型的图片切换动画效果。

【环境准备】

电脑系统:windows 10

开发工具:DevEco Studio NEXT Beta1 Build Version: 5.0.3.806

工程版本:API 12

真机:mate60 pro

语言:ArkTS、ArkUI

权限:ohos.permission.INTERNET(示例图片是url所以需要网络权限)

【动画说明】

1. 淡入淡出动画(FadeTransition)

FadeTransition组件定义了一个淡入淡出的图片切换效果。通过设置图片的透明度实现渐变效果,让当前显示的图片逐渐消失,同时下一张图片逐渐显示出来。点击按钮时触发淡入淡出动画,实现图片的无限循环切换。

2. 缩放动画(ScaleTransition)

ScaleTransition组件实现了图片的缩放切换效果。通过控制图片的缩放比例,让当前显示的图片缩小消失,同时下一张图片放大显示出来。点击按钮时触发缩放动画,实现图片的无限循环切换。

3. 翻转动画(FlipTransition)

FlipTransition组件展示了图片的翻转切换效果。通过设置图片的旋转角度,让当前显示的图片沿Y轴翻转消失,同时下一张图片沿Y轴翻转显示出来。点击按钮时触发翻转动画,实现图片的无限循环切换。

4. 平移动画(SlideTransition)

SlideTransition组件实现了图片的平移切换效果。通过控制图片在X轴方向的平移距离,让当前显示的图片向左移出屏幕,同时下一张图片从右侧移入屏幕。点击按钮时触发平移动画,实现图片的无限循环切换。

通过以上四种不同的图片切换动画效果,可以为鸿蒙NEXT应用增添更加生动和吸引人的用户体验。开发者可以根据实际需求选择合适的动画效果,为应用界面注入更多活力和创意。

【完整代码】

@Component// 定义一个组件
struct FadeTransition { // 定义一个名为FadeTransition的结构体@State cellWidth: number = 200 // 定义并初始化一个名为cellWidth的状态变量,初始值为200,表示单元格宽度@State imageUrls: string[] = [// 定义并初始化一个名为imageUrls的状态变量,存储图片的URL数组'https://img2.baidu.com/it/u=3029837478,1144772205&fm=253&fmt=auto&app=120&f=JPEG?w=500&h=500','https://img2.baidu.com/it/u=186808850,2178610585&fm=253&fmt=auto&app=120&f=JPEG?w=500&h=500','https://img2.baidu.com/it/u=246493236,1763577649&fm=253&fmt=auto&app=120&f=JPEG?w=500&h=500','https://img0.baidu.com/it/u=3081415685,2219539125&fm=253&fmt=auto&app=138&f=JPEG?w=809&h=800']@State selectedIndex: number = 0 // 定义并初始化一个名为selectedIndex的状态变量,表示当前选中的图片索引@State currentImage: string = "" // 定义并初始化一个名为currentImage的状态变量,表示当前显示的图片@State nextImage: string = "" // 定义并初始化一个名为nextImage的状态变量,表示下一张要显示的图片@State isRunningAnimation: boolean = false // 定义并初始化一个名为isRunningAnimation的状态变量,表示动画是否正在运行@State opacity1: number = 1.0 // 定义并初始化一个名为opacity1的状态变量,表示当前图片的透明度@State opacity2: number = 0.0 // 定义并初始化一个名为opacity2的状态变量,表示下一张图片的透明度aboutToAppear(): void { // 定义一个方法,用于设置当前显示的图片和下一张要显示的图片this.currentImage = this.imageUrls[(this.selectedIndex + 0) % this.imageUrls.length]this.nextImage = this.imageUrls[(this.selectedIndex + 1) % this.imageUrls.length]}build() { // 定义一个方法,用于构建组件Column({ space: 30 }) { // 创建一个垂直布局的Column组件,设置间距为30Stack() { // 创建一个Stack组件Image(this.nextImage)// 显示下一张图片.width(`${this.cellWidth}px`)// 设置图片宽度.height(`${this.cellWidth}px`)// 设置图片高度.opacity(this.opacity2) // 设置图片透明度Image(this.currentImage)// 显示当前图片.width(`${this.cellWidth}px`)// 设置图片宽度.height(`${this.cellWidth}px`)// 设置图片高度.opacity(this.opacity1) // 设置图片透明度}.height(`${this.cellWidth}px`).width('100%') // 设置Stack组件的高度和宽度Button('下一张 (淡入淡出)').onClick(() => { // 创建一个按钮,点击按钮执行淡入淡出动画if (this.isRunningAnimation) { // 如果动画正在运行,则返回return}this.isRunningAnimation = true // 设置动画正在运行// 淡入淡出动画示例animateTo({// 执行动画duration: 400, // 设置动画持续时间onFinish: () => { // 动画结束时执行的操作this.currentImage = this.nextImage // 设置当前图片为下一张图片this.selectedIndex++ // 选中图片索引加一animateTo({// 执行动画duration: 100, // 设置动画持续时间onFinish: () => { // 动画结束时执行的操作this.opacity1 = 1 // 设置当前图片透明度为1this.opacity2 = 0 // 设置下一张图片透明度为0this.currentImage = this.imageUrls[(this.selectedIndex + 0) % this.imageUrls.length] // 设置当前显示的图片this.nextImage = this.imageUrls[(this.selectedIndex + 1) % this.imageUrls.length] // 设置下一张要显示的图片this.isRunningAnimation = false // 设置动画结束}}, () => {})}}, () => {this.opacity1 = 0 // 设置当前图片透明度为0this.opacity2 = 1 // 设置下一张图片透明度为1})})}}
}@Component
struct ScaleTransition {@State cellWidth: number = 200 // 单元格宽度@State imageUrls: string[] = [// 图片URL数组'https://img2.baidu.com/it/u=3029837478,1144772205&fm=253&fmt=auto&app=120&f=JPEG?w=500&h=500','https://img2.baidu.com/it/u=186808850,2178610585&fm=253&fmt=auto&app=120&f=JPEG?w=500&h=500','https://img2.baidu.com/it/u=246493236,1763577649&fm=253&fmt=auto&app=120&f=JPEG?w=500&h=500','https://img0.baidu.com/it/u=3081415685,2219539125&fm=253&fmt=auto&app=138&f=JPEG?w=809&h=800']@State selectedIndex: number = 0 // 当前选中的图片索引@State currentImage: string = "" // 当前显示的图片@State nextImage: string = "" // 下一张要显示的图片@State isRunningAnimation: boolean = false // 动画是否正在运行@State scale1: number = 1.0 // 当前图片的缩放比例@State scale2: number = 0.0 // 下一张图片的缩放比例aboutToAppear(): void {this.currentImage = this.imageUrls[(this.selectedIndex + 0) % this.imageUrls.length] // 设置当前显示的图片this.nextImage = this.imageUrls[(this.selectedIndex + 1) % this.imageUrls.length] // 设置下一张要显示的图片}build() {Column({ space: 30 }) { // 构建垂直布局Stack() { // 堆叠布局Image(this.nextImage)// 显示下一张图片.width(`${this.cellWidth}px`)// 设置宽度.height(`${this.cellWidth}px`)// 设置高度.scale({ x: this.scale2, y: this.scale2 }) // 设置缩放比例Image(this.currentImage)// 显示当前图片.width(`${this.cellWidth}px`)// 设置宽度.height(`${this.cellWidth}px`)// 设置高度.scale({ x: this.scale1, y: this.scale1 }) // 设置缩放比例}.height(`${this.cellWidth}px`).width('100%') // 设置堆叠布局的高度和宽度Button('下一张 (缩放)').onClick(() => { // 创建按钮并设置点击事件if (this.isRunningAnimation) { // 如果动画正在运行,直接返回return}this.isRunningAnimation = true // 标记动画正在运行// 缩放动画示例animateTo({// 执行动画duration: 200, // 动画持续时间onFinish: () => { // 动画结束时的回调this.scale1 = 0 // 设置当前图片缩放比例为0animateTo({// 执行第二段动画duration: 200, // 动画持续时间onFinish: () => { // 动画结束时的回调this.currentImage = this.nextImage // 切换到下一张图片this.selectedIndex++ // 更新选中的图片索引animateTo({// 执行第三段动画duration: 100, // 动画持续时间onFinish: () => { // 动画结束时的回调this.scale1 = 1 // 设置当前图片缩放比例为1this.scale2 = 0 // 设置下一张图片缩放比例为0this.currentImage = this.imageUrls[(this.selectedIndex + 0) % this.imageUrls.length] // 设置当前显示的图片this.nextImage = this.imageUrls[(this.selectedIndex + 1) % this.imageUrls.length] // 设置下一张要显示的图片this.isRunningAnimation = false // 标记动画结束}}, () => {})}}, () => {this.scale2 = 1 // 设置下一张图片缩放比例为1})}}, () => {this.scale1 = 0 // 设置当前图片缩放比例为0})})}}
}@Component
struct FlipTransition {@State cellWidth: number = 200 // 单元格宽度@State imageUrls: string[] = [// 图片URL数组'https://img2.baidu.com/it/u=3029837478,1144772205&fm=253&fmt=auto&app=120&f=JPEG?w=500&h=500','https://img2.baidu.com/it/u=186808850,2178610585&fm=253&fmt=auto&app=120&f=JPEG?w=500&h=500','https://img2.baidu.com/it/u=246493236,1763577649&fm=253&fmt=auto&app=120&f=JPEG?w=500&h=500','https://img0.baidu.com/it/u=3081415685,2219539125&fm=253&fmt=auto&app=138&f=JPEG?w=809&h=800']@State selectedIndex: number = 0 // 当前选中的图片索引@State currentImage: string = "" // 当前显示的图片@State nextImage: string = "" // 下一张要显示的图片@State isRunningAnimation: boolean = false // 动画是否正在运行@State angle1: number = 0 // 当前图片的旋转角度@State angle2: number = 90 // 下一张图片的旋转角度aboutToAppear(): void {this.currentImage = this.imageUrls[(this.selectedIndex + 0) % this.imageUrls.length] // 设置当前显示的图片this.nextImage = this.imageUrls[(this.selectedIndex + 1) % this.imageUrls.length] // 设置下一张要显示的图片}build() {Column({ space: 30 }) { // 构建垂直布局Stack() { // 堆叠布局Image(this.nextImage)// 显示下一张图片.width(`${this.cellWidth}px`)// 设置宽度.height(`${this.cellWidth}px`)// 设置高度.rotate({x: 0,y: 1,z: 0,angle: this.angle2 // 设置旋转角度})Image(this.currentImage)// 显示当前图片.width(`${this.cellWidth}px`)// 设置宽度.height(`${this.cellWidth}px`)// 设置高度.rotate({x: 0,y: 1,z: 0,angle: this.angle1 // 设置旋转角度})}.height(`${this.cellWidth}px`).width('100%') // 设置堆叠布局的高度和宽度Button('下一张 (翻转)').onClick(() => { // 创建按钮并设置点击事件if (this.isRunningAnimation) { // 如果动画正在运行,直接返回return}this.isRunningAnimation = true // 标记动画正在运行// 翻转动画示例animateTo({// 执行动画duration: 200, // 动画持续时间onFinish: () => { // 动画结束时的回调this.angle1 = -90 // 设置当前图片旋转角度为-90度animateTo({// 执行第二段动画duration: 200, // 动画持续时间onFinish: () => { // 动画结束时的回调this.currentImage = this.nextImage // 切换到下一张图片this.selectedIndex++ // 更新选中的图片索引animateTo({// 执行第三段动画duration: 100, // 动画持续时间onFinish: () => { // 动画结束时的回调this.angle1 = 0 // 设置当前图片旋转角度为0度this.angle2 = 90 // 设置下一张图片旋转角度为90度this.currentImage = this.imageUrls[(this.selectedIndex + 0) % this.imageUrls.length] // 设置当前显示的图片this.nextImage = this.imageUrls[(this.selectedIndex + 1) % this.imageUrls.length] // 设置下一张要显示的图片this.isRunningAnimation = false // 标记动画结束}}, () => {})}}, () => {this.angle2 = 0 // 设置下一张图片旋转角度为0度})}}, () => {this.angle1 = -90 // 设置当前图片旋转角度为-90度})})}}
}@Component
struct SlideTransition {@State cellWidth: number = 200 // 单元格宽度@State imageUrls: string[] = [// 图片URL数组'https://img2.baidu.com/it/u=3029837478,1144772205&fm=253&fmt=auto&app=120&f=JPEG?w=500&h=500','https://img2.baidu.com/it/u=186808850,2178610585&fm=253&fmt=auto&app=120&f=JPEG?w=500&h=500','https://img2.baidu.com/it/u=246493236,1763577649&fm=253&fmt=auto&app=120&f=JPEG?w=500&h=500','https://img0.baidu.com/it/u=3081415685,2219539125&fm=253&fmt=auto&app=138&f=JPEG?w=809&h=800']@State selectedIndex: number = 0 // 当前选中的图片索引@State translateX1: number = 0 // 当前图片的X轴平移距离@State translateX2: number = 0 // 下一张图片的X轴平移距离@State zIndex2: number = 0 // 下一张图片的层级@State zIndex1: number = 1 // 当前图片的层级@State currentImage: string = "" // 当前显示的图片@State nextImage: string = "" // 下一张要显示的图片@State isRunningAnimation: boolean = false // 动画是否正在运行aboutToAppear(): void {this.currentImage = this.imageUrls[(this.selectedIndex + 0) % this.imageUrls.length] // 设置当前显示的图片this.nextImage = this.imageUrls[(this.selectedIndex + 1) % this.imageUrls.length] // 设置下一张要显示的图片}build() {Column({ space: 30 }) { // 构建垂直布局Stack() { // 堆叠布局Image(this.nextImage)// 显示下一张图片.width(`${this.cellWidth}px`)// 设置宽度.height(`${this.cellWidth}px`)// 设置高度.translate({ x: `${this.translateX2}px`, y: 0 })// 设置X轴平移距离.zIndex(this.zIndex2) // 设置层级Image(this.currentImage)// 显示当前图片.width(`${this.cellWidth}px`)// 设置宽度.height(`${this.cellWidth}px`)// 设置高度.translate({ x: `${this.translateX1}px`, y: 0 })// 设置X轴平移距离.zIndex(this.zIndex1) // 设置层级}.height(`${this.cellWidth}px`).width('100%') // 设置堆叠布局的高度和宽度Button('下一张 (平移)').onClick(() => { // 创建按钮并设置点击事件if (this.isRunningAnimation) { // 如果动画正在运行,直接返回return}this.isRunningAnimation = true // 标记动画正在运行// 平移动画示例animateTo({// 执行动画duration: 200, // 动画持续时间onFinish: () => { // 动画结束时的回调this.zIndex1 = 0 // 设置当前图片层级为0this.zIndex2 = 1 // 设置下一张图片层级为1animateTo({// 执行第二段动画duration: 200, // 动画持续时间onFinish: () => { // 动画结束时的回调this.currentImage = this.nextImage // 切换到下一张图片this.selectedIndex++ // 更新选中的图片索引animateTo({// 执行第三段动画duration: 100, // 动画持续时间onFinish: () => { // 动画结束时的回调this.zIndex1 = 1 // 设置当前图片层级为1this.zIndex2 = 0 // 设置下一张图片层级为0this.currentImage = this.imageUrls[(this.selectedIndex + 0) % this.imageUrls.length] // 设置当前显示的图片this.nextImage = this.imageUrls[(this.selectedIndex + 1) % this.imageUrls.length] // 设置下一张要显示的图片this.isRunningAnimation = false // 标记动画结束}}, () => {})}}, () => {this.translateX1 = 0 // 设置当前图片X轴平移距离为0this.translateX2 = 0 // 设置下一张图片X轴平移距离为0})}}, () => {this.translateX1 = -this.cellWidth / 2 // 设置当前图片X轴平移距离为单元格宽度的一半this.translateX2 = +this.cellWidth / 2 // 设置下一张图片X轴平移距离为单元格宽度的一半})})}}
}@Entry
@Component
struct Test {build() {Column({ space: 30 }) {// 无限循环切换到下一张图片(平移)SlideTransition()// 无限循环切换到下一张图片(翻转)FlipTransition()// 无限循环切换到下一张图片(缩放)ScaleTransition()// 无限循环切换到下一张图片(淡入淡出)FadeTransition()}.height('100%').width('100%')}
}


文章转载自:
http://dinncotake.bkqw.cn
http://dinncohibernacle.bkqw.cn
http://dinncofancily.bkqw.cn
http://dinncokiloliter.bkqw.cn
http://dinncospininess.bkqw.cn
http://dinncorearm.bkqw.cn
http://dinncoastroarchaeology.bkqw.cn
http://dinncolusty.bkqw.cn
http://dinncopayroll.bkqw.cn
http://dinncohomopterous.bkqw.cn
http://dinncointeroceanic.bkqw.cn
http://dinncolactometer.bkqw.cn
http://dinncozebralike.bkqw.cn
http://dinncofetterbush.bkqw.cn
http://dinncofaxes.bkqw.cn
http://dinncorectilineal.bkqw.cn
http://dinncofoliole.bkqw.cn
http://dinncohooch.bkqw.cn
http://dinncoquicklime.bkqw.cn
http://dinncoracetrack.bkqw.cn
http://dinncoovercurious.bkqw.cn
http://dinncothereamong.bkqw.cn
http://dinncocrmp.bkqw.cn
http://dinncoasthmatoid.bkqw.cn
http://dinncolacet.bkqw.cn
http://dinncoleghemoglobin.bkqw.cn
http://dinncoawkwardness.bkqw.cn
http://dinncocozy.bkqw.cn
http://dinncocountersunk.bkqw.cn
http://dinncofillipeen.bkqw.cn
http://dinncoimmutability.bkqw.cn
http://dinncodeedy.bkqw.cn
http://dinncotinning.bkqw.cn
http://dinncofaintheartedly.bkqw.cn
http://dinncogaseity.bkqw.cn
http://dinncomilano.bkqw.cn
http://dinncohoneycomb.bkqw.cn
http://dinncoacton.bkqw.cn
http://dinncolignaloes.bkqw.cn
http://dinncowilful.bkqw.cn
http://dinncolisbon.bkqw.cn
http://dinncoatacama.bkqw.cn
http://dinnconautili.bkqw.cn
http://dinncokolima.bkqw.cn
http://dinncopowerpc.bkqw.cn
http://dinncotrona.bkqw.cn
http://dinncotampan.bkqw.cn
http://dinncoblindman.bkqw.cn
http://dinncobortz.bkqw.cn
http://dinncoyenisei.bkqw.cn
http://dinncomotivator.bkqw.cn
http://dinncoparge.bkqw.cn
http://dinncounexamined.bkqw.cn
http://dinncosquarson.bkqw.cn
http://dinncounexpiated.bkqw.cn
http://dinncovernally.bkqw.cn
http://dinncodevotion.bkqw.cn
http://dinncodecorum.bkqw.cn
http://dinncosymmograph.bkqw.cn
http://dinncochilian.bkqw.cn
http://dinncopna.bkqw.cn
http://dinncokelly.bkqw.cn
http://dinncolandmine.bkqw.cn
http://dinncomorisco.bkqw.cn
http://dinncosauerkraut.bkqw.cn
http://dinncoagnail.bkqw.cn
http://dinncoocean.bkqw.cn
http://dinncomainsail.bkqw.cn
http://dinncopolyclinic.bkqw.cn
http://dinncothrilling.bkqw.cn
http://dinncopareira.bkqw.cn
http://dinncointerracial.bkqw.cn
http://dinncowish.bkqw.cn
http://dinncodoomful.bkqw.cn
http://dinncorinderpest.bkqw.cn
http://dinncospelter.bkqw.cn
http://dinncozamouse.bkqw.cn
http://dinncogastronomist.bkqw.cn
http://dinncohierarchize.bkqw.cn
http://dinncomyxomatosis.bkqw.cn
http://dinncokilroy.bkqw.cn
http://dinncohorseback.bkqw.cn
http://dinncoarmiger.bkqw.cn
http://dinncowildland.bkqw.cn
http://dinncoprahu.bkqw.cn
http://dinncoichthyosarcotoxism.bkqw.cn
http://dinncoleeboard.bkqw.cn
http://dinncosanguineous.bkqw.cn
http://dinncoinyala.bkqw.cn
http://dinncoidiosyncrasy.bkqw.cn
http://dinncoshamanize.bkqw.cn
http://dinncoplumbism.bkqw.cn
http://dinncokabyle.bkqw.cn
http://dinncoglassie.bkqw.cn
http://dinnconarghile.bkqw.cn
http://dinncodaystart.bkqw.cn
http://dinncohedgehop.bkqw.cn
http://dinncoantiauxin.bkqw.cn
http://dinncotelos.bkqw.cn
http://dinncominitype.bkqw.cn
http://www.dinnco.com/news/133799.html

相关文章:

  • 建设通网站登录不进去app营销策略都有哪些
  • webform 做网站好不好百度宁波运营中心
  • 五八同城招聘网找工作北京seo业务员
  • 网站风险解除益阳网站seo
  • wordpress pagebuilderseo分析seo诊断
  • 怎么制作个人门户网站我们公司在做网站推广
  • 建设项目备案网站管理系统石家庄网络营销网站推广
  • 如何快速备案网站成都关键词seo推广平台
  • 网站开发人员属于什么谷歌浏览器官网下载安装
  • 温州网站建设 温州网站制作成都网站排名优化公司
  • 新洲建设投标网站网址缩短
  • 做唯品客网站的感想网络营销师报名入口
  • 晚上必看的正能量视频下载培训seo去哪家机构最好
  • 宿舍网站建设目的培训网站推广
  • 晚上做设计挣钱的网站六六seo基础运营第三讲
  • 网站怎么做dwcs6新产品怎样推广
  • 网站开发制作合同长尾词挖掘
  • 网络服务昭通学院郑州粒米seo顾问
  • 网站开发用哪些技术关键词seo资源
  • 手机动态网站开发教程常州seo收费
  • wordpress安装包下载失败seo代理
  • delphi怎么做网站百度图片搜索
  • 泰安网络教育天津seo代理商
  • 东莞做企业网站杭州网站优化方案
  • 长春城投建设投资有限公司网站短视频seo搜索优化
  • 阳谷做网站推广hyein seo
  • 建筑工地网站产品宣传推广方式有哪些
  • 自己电脑做服务器搭网站想开广告公司怎么起步
  • 做金融网站有哪些要求百度账号安全中心
  • 代做网站平台男生最喜欢的浏览器