新闻详情

新闻详情

首页 / 资讯中心 / 详情

Harmony鸿蒙实战开发-抽奖app【源码在文末】

发布时间:2026/9/17 11:50:42来源:尧图网络
Harmony鸿蒙实战开发-抽奖app【源码在文末】
Harmony鸿蒙实战开发-抽奖app【源码在文末】文章目录Harmony鸿蒙实战开发-抽奖app【源码在文末】一、运行演示二、部分代码三、源码运行工具DevEco Studio一、运行演示二、部分代码/* * Copyright (c) 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import window from ohos.window; import Logger from ../common/utils/Logger; import DrawModel from ../viewmodel/DrawModel; import PrizeDialog from ../view/PrizeDialog; import PrizeData from ../viewmodel/PrizeData; import StyleConstants from ../common/constants/StyleConstants; import CommonConstants from ../common/constants/CommonConstants; // 获取上下文 let context getContext(this); Entry Component struct CanvasPage { private settings: RenderingContextSettings new RenderingContextSettings(true); private canvasContext: CanvasRenderingContext2D new CanvasRenderingContext2D(this.settings); State drawModel: DrawModel new DrawModel(); State screenWidth: number 0; State screenHeight: number 0; State rotateDegree: number 0; State enableFlag: boolean true; State prizeData: PrizeData new PrizeData(); dialogController: CustomDialogController new CustomDialogController({ builder: PrizeDialog({ prizeData: $prizeData, enableFlag: $enableFlag }), autoCancel: false }); aboutToAppear() { // 获取屏幕宽高不包括导航视图的高度 window.getLastWindow(context) .then((windowClass: window.Window) { let windowProperties windowClass.getWindowProperties(); this.screenWidth px2vp(windowProperties.windowRect.width); this.screenHeight px2vp(windowProperties.windowRect.height); }) .catch((error: Error) { Logger.error(获取窗口大小失败。原因 JSON.stringify(error)); }) } build() { Stack({ alignContent: Alignment.Center }) { Canvas(this.canvasContext) .width(StyleConstants.FULL_PERCENT) .height(StyleConstants.FULL_PERCENT) .onReady(() { this.drawModel.draw(this.canvasContext, this.screenWidth, this.screenHeight); }) .rotate({ x: 0, y: 0, z: 1, angle: this.rotateDegree, centerX: this.screenWidth / CommonConstants.TWO, centerY: this.screenHeight / CommonConstants.TWO }) Image($r(app.media.ic_center)) .width(StyleConstants.CENTER_IMAGE_WIDTH) .height(StyleConstants.CENTER_IMAGE_HEIGHT) .enabled(this.enableFlag) .onClick(() { this.enableFlag !this.enableFlag; this.startAnimator(); }) } .width(StyleConstants.FULL_PERCENT) .height(StyleConstants.FULL_PERCENT) .backgroundImage($r(app.media.ic_background), ImageRepeat.NoRepeat) .backgroundImageSize({ width: StyleConstants.FULL_PERCENT, height: StyleConstants.BACKGROUND_IMAGE_SIZE }) } /** * 启动动画 */ startAnimator() { let randomAngle Math.round(Math.random() * CommonConstants.CIRCLE); // 获取奖品信息 this.prizeData this.drawModel.showPrizeData(randomAngle); animateTo({ duration: CommonConstants.DURATION, curve: Curve.Ease, delay: 0, iterations: 1, playMode: PlayMode.Normal, onFinish: () { this.rotateDegree CommonConstants.ANGLE - randomAngle; // 显示奖品信息弹窗 this.dialogController.open(); } }, () { this.rotateDegree CommonConstants.CIRCLE * CommonConstants.FIVE CommonConstants.ANGLE - randomAngle; }) } }三、源码通过百度网盘分享的文件…zip链接https://pan.baidu.com/s/1xbu6QWOItJCKOzAaG49Piw文件已经加密请联系请加下方wx号获取源码仅一杯奶茶钱 号码Lvnvn0508
网站建设高端定制企业官网
RELATED

相关资讯

更多精彩内容,欢迎继续阅读

较早相关资讯

最新相关资讯

OpenUSD 命名空间编辑(Namespace Editing)实战指南:用 UsdNamespaceEditor 安全地跨层删除与移动 Prim 2026/9/17 12:29:51

OpenUSD 命名空间编辑(Namespace Editing)实战指南:用 UsdNamespaceEditor 安全地跨层删除与移动 Prim

OpenUSD 命名空间编辑(Namespace Editing)实战指南:用 UsdNamespaceEditor 安全地跨层删除与移动 Prim 【免费下载链接】OpenUSD Universal Scene Description 项目地址: https://gitcode.com/GitHub_Trending/ope/OpenUSD 命名空间编…

阅读更多 →
Zcash 1.1.1-rc2 版本解读:zcash-cli 参数隐私与 scriptSig SIGHASH 类型解码 2026/9/17 12:29:51

Zcash 1.1.1-rc2 版本解读:zcash-cli 参数隐私与 scriptSig SIGHASH 类型解码

Zcash 1.1.1-rc2 版本解读:zcash-cli 参数隐私与 scriptSig SIGHASH 类型解码 【免费下载链接】zcash Zcash - Internet Money 项目地址: https://gitcode.com/GitHub_Trending/zc/zcash 本文基于 Zcash 开源仓库的官方发布说明 release-notes-1.1.1-rc2.md&…

阅读更多 →
泛微OA流程三要素校验:表单、路径、流转闭环配置指南 2026/9/17 12:29:51

泛微OA流程三要素校验:表单、路径、流转闭环配置指南

简介:本资源是一份面向泛微OA系统管理员与流程配置人员的实操型搭建指南,聚焦低代码流程引擎的核心配置能力,解决从零构建审批流、人事表单等业务流程的实际难题。文档以“加值班登记单”为完整案例,系统覆盖新建表单(…

阅读更多 →
千问办公入驻 deepin 应用商店,一站式 AI 办公让 Linux 日常生产力再升级 2026/9/17 12:29:51

千问办公入驻 deepin 应用商店,一站式 AI 办公让 Linux 日常生产力再升级

千问办公:一站式 AI 办公新势力千问办公是阿里巴巴全新推出的一站式 AI 办公平台,已全面覆盖桌面端、网页端,并深度接入钉钉生态。它以千问系列大模型为旗舰驱动,拥有百万级超长上下文记忆、原生多模态感知能力以及业界领先的代码…

阅读更多 →
STM32H750寄存器级SD卡读写:SDMMC驱动与FATFS移植实战 2026/9/17 12:29:51

STM32H750寄存器级SD卡读写:SDMMC驱动与FATFS移植实战

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

阅读更多 →
基于SpringBoot框架的大学生电子健康档案管理系统 2026/9/17 12:26:51

基于SpringBoot框架的大学生电子健康档案管理系统

目录 1.项目介绍 1 1.1设计背景 1 1.2 设计目的和意义 1 1.3 国内外研究现状 2 1.4软件架构 3 2 系统需求分析 3 2.1 系统目标 3 2.2 系统的功能要求 3 2.2.1 前台功能 3 2.2.2 后台功能 4 2.3 系统的性能需求 4 2.4 系统的数据要求 4 2.4.1 数据的性质 4 2.4.2 数据字典 5 2.4…

阅读更多 →

今日资讯

本周资讯

本月资讯

看完文章仍有疑问?

联系尧图顾问,获取一对一建站咨询

立即免费咨询 📞 400-888-8888
📞