chinese直男口爆体育生外卖, 99久久er热在这里只有精品99, 又色又爽又黄18禁美女裸身无遮挡, gogogo高清免费观看日本电视,私密按摩师高清版在线,人妻视频毛茸茸,91论坛 兴趣闲谈,欧美 亚洲 精品 8区,国产精品久久久久精品免费

0
  • 聊天消息
  • 系統(tǒng)消息
  • 評(píng)論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習(xí)在線課程
  • 觀看技術(shù)視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會(huì)員中心
創(chuàng)作中心

完善資料讓更多小伙伴認(rèn)識(shí)你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

玩嗨OpenHarmony:基于OpenHarmony的ArkUI翻頁時(shí)鐘

共熵服務(wù)中心 ? 來源:未知 ? 2022-12-05 20:15 ? 次閱讀
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

原文引自:51CTO 開源基礎(chǔ)軟件社區(qū) #夏日挑戰(zhàn)賽# OpenHarmony - 《ArkUI(TS)開發(fā)翻頁時(shí)鐘

63824d32-7496-11ed-8abf-dac502259ad0.png

1. 項(xiàng)目背景

翻頁時(shí)鐘(Flip Clock)是一種有趣的機(jī)電數(shù)字計(jì)時(shí)設(shè)備,用電腦動(dòng)畫的方式實(shí)現(xiàn)翻頁時(shí)鐘,也是一種特別的復(fù)古UI交互體驗(yàn)。

本項(xiàng)目豈在通過OpenHarmony的ArkUI框架,用TS擴(kuò)展的聲明式開發(fā)范式eTS,來實(shí)現(xiàn)翻頁時(shí)鐘的體驗(yàn)。

本項(xiàng)目的開發(fā)環(huán)境如下:

  • 工具版本:DevEco Studio 3.0 Beta4

  • SDK版本:3.1.6.6(API Version 8 Release)

具體實(shí)現(xiàn)的效果是這樣的:

63a47eca-7496-11ed-8abf-dac502259ad0.gif

本項(xiàng)目的主要知識(shí)點(diǎn)如下:

  • UI狀態(tài):@Prop、@Link、@Watch

  • 形狀裁剪屬性:clip

  • 顯式動(dòng)畫:animateTo

2. eTS開發(fā)范式基于eTS的聲明式開發(fā)范式的方舟開發(fā)框架是一套開發(fā)極簡(jiǎn)、高性能、跨設(shè)備應(yīng)用的UI開發(fā)框架,支持開發(fā)者高效的構(gòu)建跨設(shè)備應(yīng)用UI界面。

使用基于eTS的聲明式開發(fā)范式的方舟開發(fā)框架,采用更接近自然語義的編程方式,讓開發(fā)者可以直觀地描述UI界面,不必關(guān)心框架如何實(shí)現(xiàn)UI繪制和渲染,實(shí)現(xiàn)極簡(jiǎn)高效開發(fā)。開發(fā)框架不僅從組件、動(dòng)效和狀態(tài)管理三個(gè)維度來提供UI能力,還提供了系統(tǒng)能力接口,實(shí)現(xiàn)系統(tǒng)能力的極簡(jiǎn)調(diào)用。

63e5af44-7496-11ed-8abf-dac502259ad0.png

關(guān)于語法和概念詳細(xì)請(qǐng)直接看官網(wǎng)官方文檔地址:

https://docs.openharmony.cn/pages/v3.1/zh-cn/application-dev/ui/ui-ts-overview.md/

3. 實(shí)現(xiàn)思路時(shí)鐘翻頁效果,用到四個(gè)Text組件,使用堆疊容器Stack。底層:用到兩個(gè)裁剪過后的Text上下顯示;頂層:也是用兩個(gè)裁剪后的Text做動(dòng)畫效果,進(jìn)行X軸角度旋轉(zhuǎn)。

3.1 裁剪Text

裁剪前:

63fc5e4c-7496-11ed-8abf-dac502259ad0.png

裁剪后:

64170030-7496-11ed-8abf-dac502259ad0.png

使用形狀裁剪屬性clip

裁剪Text上半部:從坐標(biāo)(0,0)往下裁剪,clip(new Rect({ width: this.width, height: this.height / 2 }))

裁剪Text下半部:從坐標(biāo)(0,height / 2)往下裁剪,clip(new Path().commands(this.bottomPath))

@Entry
@Component
struct Test {
  private width = 90
  private height = 110
  private fontSize = 70
  private defaultBgColor = '#ffe6e6e6'
  private borderRadius = 10


  // 下半部裁剪路徑
  private bottomPath = `M0 ${vp2px(this.height / 2)}
  L${vp2px(this.width)} ${vp2px(this.height / 2)}
  L${vp2px(this.width)} ${vp2px(this.height)}
  L0 ${vp2px(this.height)} Z`


  build() {
    Row() {


      Text('24')
        .width(this.width)
        .height(this.height)
        .fontColor(Color.Black)
        .fontSize(this.fontSize)
        .textAlign(TextAlign.Center)
        .borderRadius(this.borderRadius)
        .backgroundColor(this.defaultBgColor)
        .clip(new Rect({ width: this.width, height: this.height / 2 }))


      Text('25')
        .margin({left:20})
        .width(this.width)
        .height(this.height)
        .fontColor(Color.Black)
        .fontSize(this.fontSize)
        .textAlign(TextAlign.Center)
        .borderRadius(this.borderRadius)
        .backgroundColor(this.defaultBgColor)
        .clip(new Path().commands(this.bottomPath))


    }.width('100%')
    .height('100%')
    .justifyContent(FlexAlign.Center)
  }
}
3.2放入堆疊容器

四個(gè)裁剪后的Text放入到堆疊容器中(代碼片段):

    Stack() {
      // 底層文字上部
      Text(this.newValue)
        ......
        .clip(new Rect({ width: this.width, height: this.height / 2 }))


      // 底層文字下部
      Text(this.oldValue)
        ......
        .clip(new Path().commands(this.bottomPath))


      // 頂層文字上部動(dòng)畫
      Text(this.oldValue)
        ......
        .clip(new Rect({ width: this.width, height: this.height / 2 }))
        .rotate({ x: 1, centerY: '50%', angle: this.angleTop })


      // 頂層文字下部動(dòng)畫
      Text(this.newValue)
        ......
        .margin({ top: 3 })
        .clip(new Path().commands(this.bottomPath))
        .rotate({ x: 1, centerY: '50%', angle: this.angleBottom })
    }
3.3使用顯式動(dòng)畫

先頂層上部的動(dòng)畫,上部旋轉(zhuǎn)角度從0到90停止,接下來執(zhí)行頂層下部的動(dòng)畫,下部旋轉(zhuǎn)角度從-90到0停止,停止完后重置初始狀態(tài),上部旋轉(zhuǎn)角度 = 0、下部旋轉(zhuǎn)角度 = -90(代碼片段)

  /**
   * 啟動(dòng)頂層文字上部動(dòng)畫
   */
  startTopAnimate() {
    animateTo({
      duration: 400,
      onFinish: () => {
        this.startBottomAnimate()
        this.animateBgColor = '#ffededed'
      }
    }, () => {
      this.angleTop = 90
      this.animateBgColor = '#ffc5c5c5'
    })
  }


  /**
   * 啟動(dòng)頂層文字下部動(dòng)畫
   */
  startBottomAnimate() {
    animateTo({
      duration: 400,
      onFinish: () => {
        this.angleTop = 0
        this.angleBottom = -90
        this.animateBgColor = this.defaultBgColor
        this.oldValue = this.newValue
      }
    }, () => {
      this.angleBottom = 0
      this.animateBgColor = this.defaultBgColor
    })
  }
3.4組件封裝

翻頁邏輯封裝成組件,提供給外部調(diào)用,根據(jù)外部傳入的雙向數(shù)據(jù)綁定:newValue,監(jiān)聽數(shù)據(jù)變化,有變化則啟動(dòng)翻頁動(dòng)畫(代碼片段):

@Component
export struct FlipPage {
  // 頂層上部動(dòng)畫角度
  @State angleTop: number = 0
  // 頂層下部動(dòng)畫角度
  @State angleBottom: number = -90
  // 舊值
  @Prop oldValue: string
  // 新值,加入監(jiān)聽
  @Link @Watch('valueChange') newValue: string


  /**
   * 監(jiān)聽新值變化
   */
  valueChange() {
    if (this.oldValue === this.newValue) return
    this.startTopAnimate()
  }


  build() {
    Stack() {
      // 底層文字上部
      Text(this.newValue)
        ......
        .clip(new Rect({ width: this.width, height: this.height / 2 }))


      // 底層文字下部
      Text(this.oldValue)
        ......
        .clip(new Path().commands(this.bottomPath))


      // 頂層文字上部動(dòng)畫
      Text(this.oldValue)
        ......
        .clip(new Rect({ width: this.width, height: this.height / 2 }))
        .rotate({ x: 1, centerY: '50%', angle: this.angleTop })


      // 頂層文字下部動(dòng)畫
      Text(this.newValue)
        ......
        .margin({ top: 3 })
        .clip(new Path().commands(this.bottomPath))
        .rotate({ x: 1, centerY: '50%', angle: this.angleBottom })
    }
  }
  /**
  * 啟動(dòng)頂層文字上部動(dòng)畫
  */
  startTopAnimate() {
    ......
  }
3.5外部調(diào)用

界面加載成功后,開啟循環(huán)定時(shí)器setInterval、間隔1秒更新時(shí)間。更改newValue的值,翻頁組件內(nèi)部進(jìn)行動(dòng)畫翻頁。

import { FlipPage } from '../componet/FlipPage'


@Entry
@Component
struct Index {
  // 小時(shí)-舊值
  @State oldHours: string = ''
  // 小時(shí)-新值
  @State newHours: string = ''
  // 分鐘-舊值
  @State oldMinutes: string = ''
  // 分鐘-新值
  @State newMinutes: string = ''
  // 秒數(shù)-舊值
  @State oldSeconds: string = ''
  // 秒數(shù)-新值
  @State newSeconds: string = ''


  @Builder Colon() {
    Column() {
      Circle().width(8).height(8).fill(Color.Black)
      Circle().width(8).height(8).fill(Color.Black).margin({ top: 10 })
    }.padding(10)
  }


  build() {
    Row() {
      // 翻頁組件-顯示小時(shí)
      FlipPage({ oldValue: this.oldHours, newValue: $newHours })
      // 冒號(hào)
      this.Colon()
      // 翻頁組件-顯示分鐘
      FlipPage({ oldValue: this.oldMinutes, newValue: $newMinutes })
      // 冒號(hào)
      this.Colon()
      // 翻頁組件-顯示秒數(shù)
      FlipPage({ oldValue: this.oldSeconds, newValue: $newSeconds })
    }
    .justifyContent(FlexAlign.Center)
    .width('100%')
    .height('100%')
    .onAppear(() => {
      // 開啟定時(shí)器
      this.initDate()
      setInterval(() => {
        this.updateDate()
      }, 1000)
    })
  }


  /**
   * 初始化時(shí)間
   */
  initDate() {
    let date = new Date()
    // 設(shè)置小時(shí)
    this.oldHours = this.format(date.getHours())
    // 設(shè)置分鐘
    this.oldMinutes = this.format(date.getMinutes())
    // 設(shè)置秒數(shù)
    this.oldSeconds = this.format(date.getSeconds())
    // 設(shè)置新的秒數(shù)
    this.newSeconds = date.getSeconds() + 1 === 60 ? '00' : this.format(date.getSeconds() + 1)
  }


  /**
   * 更新時(shí)間
   */
  updateDate() {
    let date = new Date()
    console.log(`${date.getHours()}時(shí)${date.getMinutes()}${date.getSeconds()}秒`)
    // 當(dāng)新值改變,才有動(dòng)畫
    if (date.getSeconds() === 59) {
      this.newSeconds = '00'
      this.newMinutes = date.getMinutes() + 1 === 60 ? '00' : this.format(date.getMinutes() + 1)
      if (date.getMinutes() === 59) {
        this.newHours = date.getHours() + 1 === 24 ? '00' : this.format(date.getHours() + 1)
      }
    } else {
      this.newSeconds = this.format(date.getSeconds() + 1)
    }
  }


  /**
   * 不足十位前面補(bǔ)零
   */
  format(param) {
    let value = '' + param
    if (param < 10) {
      value = '0' + param
    }
    return value
  }
}
4.總結(jié)根據(jù)上面的實(shí)現(xiàn)思路和5個(gè)步驟流程,相信你也掌握了翻頁時(shí)鐘原理,拆分成一步一步還是很簡(jiǎn)單的,最主要還是對(duì)API的熟悉和聲明式語法的掌握。HarmonyOS的API是根據(jù)OpenHarmony去更新的,兩者區(qū)別語法都一樣,只是OpenHarmony的API比較新,功能比較完善和成熟的,所以本項(xiàng)目直接使用OpenHarmony SDK開發(fā)。645d457c-7496-11ed-8abf-dac502259ad0.gif 本文完寫在最后我們最近正帶著大家玩嗨OpenHarmony。如果你有好玩的東東,歡迎投稿,讓我們一起嗨起來!有點(diǎn)子,有想法,有Demo,立刻聯(lián)系我們:合作郵箱:zzliang@atomsource.org
646c344c-7496-11ed-8abf-dac502259ad0.gif

6497e1fa-7496-11ed-8abf-dac502259ad0.png

64cde110-7496-11ed-8abf-dac502259ad0.png64de3970-7496-11ed-8abf-dac502259ad0.png6501ab08-7496-11ed-8abf-dac502259ad0.png

650cc628-7496-11ed-8abf-dac502259ad0.png

652c6190-7496-11ed-8abf-dac502259ad0.png

654d7074-7496-11ed-8abf-dac502259ad0.png

65721000-7496-11ed-8abf-dac502259ad0.png

65a1d57e-7496-11ed-8abf-dac502259ad0.png

65ca526a-7496-11ed-8abf-dac502259ad0.png

663c7336-7496-11ed-8abf-dac502259ad0.png

66afe622-7496-11ed-8abf-dac502259ad0.png

66c4d104-7496-11ed-8abf-dac502259ad0.png

66d3bbba-7496-11ed-8abf-dac502259ad0.png

66fd970a-7496-11ed-8abf-dac502259ad0.png

671687ba-7496-11ed-8abf-dac502259ad0.png

672c55fe-7496-11ed-8abf-dac502259ad0.png

674d70ea-7496-11ed-8abf-dac502259ad0.png

676f6902-7496-11ed-8abf-dac502259ad0.png

6781e2b2-7496-11ed-8abf-dac502259ad0.png


原文標(biāo)題:玩嗨OpenHarmony:基于OpenHarmony的ArkUI翻頁時(shí)鐘

文章出處:【微信公眾號(hào):開源技術(shù)服務(wù)中心】歡迎添加關(guān)注!文章轉(zhuǎn)載請(qǐng)注明出處。


聲明:本文內(nèi)容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點(diǎn)僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場(chǎng)。文章及其配圖僅供工程師學(xué)習(xí)之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問題,請(qǐng)聯(lián)系本站處理。 舉報(bào)投訴
  • 開源技術(shù)
    +關(guān)注

    關(guān)注

    0

    文章

    389

    瀏覽量

    8686
  • OpenHarmony
    +關(guān)注

    關(guān)注

    31

    文章

    3920

    瀏覽量

    20676

原文標(biāo)題:玩嗨OpenHarmony:基于OpenHarmony的ArkUI翻頁時(shí)鐘

文章出處:【微信號(hào):開源技術(shù)服務(wù)中心,微信公眾號(hào):共熵服務(wù)中心】歡迎添加關(guān)注!文章轉(zhuǎn)載請(qǐng)注明出處。

收藏 人收藏
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

    評(píng)論

    相關(guān)推薦
    熱點(diǎn)推薦

    OpenHarmony年度課題管理辦法

    OpenHarmony年度課題管理辦法V1.0 第一章 總則 第一條 宗旨 圍繞終端操作系統(tǒng)所面臨的技術(shù)挑戰(zhàn),OpenHarmony項(xiàng)目群技術(shù)指導(dǎo)委員會(huì)(TSC)聯(lián)合產(chǎn)學(xué)研各界,以
    的頭像 發(fā)表于 11-12 16:55 ?412次閱讀

    兩款搭載KaihongOS的開鴻開發(fā)板被評(píng)為“OpenHarmony 明星開發(fā)板”

    OpenHarmony
    深開鴻
    發(fā)布于 :2025年09月11日 10:10:02

    2025 OpenHarmony TSC年中技術(shù)與生態(tài)研討會(huì)圓滿舉辦

    2025 OpenHarmony TSC 年中技術(shù)與生態(tài)研討會(huì) 圓滿舉辦 8月1日,2025 OpenHarmony TSC年中技術(shù)與生態(tài)研討會(huì)于中國(guó)上海順利召開。 本次會(huì)議由OpenHarmony
    的頭像 發(fā)表于 08-07 12:24 ?1335次閱讀
    2025 <b class='flag-5'>OpenHarmony</b> TSC年中技術(shù)與生態(tài)研討會(huì)圓滿舉辦

    OpenHarmony2025年度競(jìng)賽訓(xùn)練營(yíng)重磅開啟

    ? OpenHarmony2025年度競(jìng)賽訓(xùn)練營(yíng) ? ? ? 活動(dòng)介紹 OpenHarmony競(jìng)賽訓(xùn)練營(yíng) 旨在引導(dǎo)高校學(xué)生進(jìn)行OpenHarmony產(chǎn)學(xué)研用,培養(yǎng)更多應(yīng)用型人才和產(chǎn)業(yè)需求有效鏈接
    的頭像 發(fā)表于 07-16 11:51 ?701次閱讀

    桃芯科技獲得OpenHarmony生態(tài)產(chǎn)品兼容性證書

    近日,由INGCHIPS自主研發(fā)的模組/開發(fā)板DB870CC1A順利通過OpenHarmony 5.0.2 Release版本兼容性測(cè)評(píng),并獲得OpenHarmony生態(tài)產(chǎn)品兼容性證書!
    的頭像 發(fā)表于 06-25 14:30 ?835次閱讀

    ArkUI-X通過Stage模型開發(fā)Android端應(yīng)用指南(一)

    簡(jiǎn)介 本文介紹將ArkUI框架擴(kuò)展到Android平臺(tái)所需要的必要的類及其使用說明,開發(fā)者基于OpenHarmony,可復(fù)用大部分的應(yīng)用代碼(生命周期等)并可以部署到Android平臺(tái),降低跨平臺(tái)
    發(fā)表于 06-24 22:16

    ArkUI-X平臺(tái)橋接Bridge說明

    。 使用場(chǎng)景及能力 使用場(chǎng)景 平臺(tái)橋接主要用于這樣的場(chǎng)景:應(yīng)用需要復(fù)用平臺(tái)的代碼,而在OpenHarmony中沒有對(duì)應(yīng)的跨平臺(tái)API(不包括UI相關(guān))實(shí)現(xiàn)。 具體可用于以下場(chǎng)景: 1、ArkUI與平臺(tái)雙向
    發(fā)表于 06-19 23:12

    ArkUI-X應(yīng)用工程結(jié)構(gòu)說明

    簡(jiǎn)介 本文檔配套ArkUI-X,將OpenHarmony ArkUI開發(fā)框架擴(kuò)展到不同的OS平臺(tái),比如Android和iOS平臺(tái),讓開發(fā)者基于ArkUI,可復(fù)用大部分的應(yīng)用代碼(UI以
    發(fā)表于 06-19 23:11

    ArkUI-X在Android上使用Fragment開發(fā)指南

    arkui_android_adapter.jar包所提供的StageFragment,StageFragment主要功能是將Android中Fragment的生命周期與OpenHarmony
    發(fā)表于 06-12 22:42

    貢獻(xiàn) OpenHarmony 庫(kù)關(guān)鍵配置

    # 貢獻(xiàn) OpenHarmony 庫(kù)關(guān)鍵配置 #自研框架#ArkUI-X#三方框架#OpenHarmony#HarmonyOS ## 創(chuàng)建第三方庫(kù) - 打開 DevEco Studio 創(chuàng)建一個(gè)
    發(fā)表于 05-28 13:46

    請(qǐng)問下,openharmony支持哪一款龍芯的開發(fā)板?有沒有開源的龍芯的openharmony源碼?

    想買個(gè)2k0300的開發(fā)板學(xué)習(xí)龍芯和openharmony,愣是沒有看到提供openharmony源碼的,也沒與看到開源的代碼。gitee上,openharmony的龍芯sig倉(cāng)庫(kù)也是關(guān)閉的,有沒有人知道現(xiàn)在是什么情況?
    發(fā)表于 04-26 13:06

    2024年OpenHarmony社區(qū)年度激勵(lì)公示

    在過去一年里,OpenHarmony項(xiàng)目群技術(shù)指導(dǎo)委員會(huì)(TSC)向所有參與者致以最誠(chéng)摯的感謝!大家的積極參與和鼎力支持推動(dòng)了OpenHarmony社區(qū)的持續(xù)繁榮與高質(zhì)量發(fā)展。OpenHarmony
    的頭像 發(fā)表于 04-21 18:17 ?914次閱讀

    【北京迅為】itop-3568 開發(fā)板openharmony鴻蒙燒寫及測(cè)試-第2章OpenHarmony v3.2-Beta4版本測(cè)試

    【北京迅為】itop-3568 開發(fā)板openharmony鴻蒙燒寫及測(cè)試-第2章OpenHarmony v3.2-Beta4版本測(cè)試
    的頭像 發(fā)表于 03-05 10:53 ?864次閱讀
    【北京迅為】itop-3568 開發(fā)板<b class='flag-5'>openharmony</b>鴻蒙燒寫及測(cè)試-第2章<b class='flag-5'>OpenHarmony</b> v3.2-Beta4版本測(cè)試

    【北京迅為】itop-3568 開發(fā)板openharmony鴻蒙燒寫及測(cè)試-第1章 體驗(yàn)OpenHarmony—燒寫鏡像

    【北京迅為】itop-3568 開發(fā)板openharmony鴻蒙燒寫及測(cè)試-第1章 體驗(yàn)OpenHarmony—燒寫鏡像
    的頭像 發(fā)表于 03-04 16:31 ?861次閱讀
    【北京迅為】itop-3568 開發(fā)板<b class='flag-5'>openharmony</b>鴻蒙燒寫及測(cè)試-第1章 體驗(yàn)<b class='flag-5'>OpenHarmony</b>—燒寫鏡像

    OpenHarmony程序分析框架論文入選ICSE 2025

      近日,ICSE 2025軟件工程實(shí)踐Track放榜,面向OpenAtom OpenHarmony(以下簡(jiǎn)稱“OpenHarmony”)的ArkTS程序分析基礎(chǔ)框架--方舟程序分析器(論文題目為
    的頭像 發(fā)表于 01-02 13:41 ?1810次閱讀
    <b class='flag-5'>OpenHarmony</b>程序分析框架論文入選ICSE 2025