女人自慰AV免费观看内涵网,日韩国产剧情在线观看网址,神马电影网特片网,最新一级电影欧美,在线观看亚洲欧美日韩,黄色视频在线播放免费观看,ABO涨奶期羡澄,第一导航fulione,美女主播操b

0
  • 聊天消息
  • 系統消息
  • 評論與回復
登錄后你可以
  • 下載海量資料
  • 學習在線課程
  • 觀看技術視頻
  • 寫文章/發帖/加入社區
會員中心
創作中心

完善資料讓更多小伙伴認識你,還能領取20積分哦,立即完善>

3天內不再提示

玩嗨OpenHarmony:基于OpenHarmony的ArkUI翻頁時鐘

共熵服務中心 ? 來源:未知 ? 2022-12-05 20:15 ? 次閱讀
原文引自:51CTO 開源基礎軟件社區 #夏日挑戰賽# OpenHarmony - 《ArkUI(TS)開發翻頁時鐘

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

1. 項目背景

翻頁時鐘(Flip Clock)是一種有趣的機電數字計時設備,用電腦動畫的方式實現翻頁時鐘,也是一種特別的復古UI交互體驗。

本項目豈在通過OpenHarmony的ArkUI框架,用TS擴展的聲明式開發范式eTS,來實現翻頁時鐘的體驗。

本項目的開發環境如下:

  • 工具版本:DevEco Studio 3.0 Beta4

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

具體實現的效果是這樣的:

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

本項目的主要知識點如下:

  • UI狀態:@Prop、@Link、@Watch

  • 形狀裁剪屬性:clip

  • 顯式動畫:animateTo

2. eTS開發范式基于eTS的聲明式開發范式的方舟開發框架是一套開發極簡、高性能、跨設備應用的UI開發框架,支持開發者高效的構建跨設備應用UI界面。

使用基于eTS的聲明式開發范式的方舟開發框架,采用更接近自然語義的編程方式,讓開發者可以直觀地描述UI界面,不必關心框架如何實現UI繪制和渲染,實現極簡高效開發。開發框架不僅從組件、動效和狀態管理三個維度來提供UI能力,還提供了系統能力接口,實現系統能力的極簡調用。

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

關于語法和概念詳細請直接看官網官方文檔地址:

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

3. 實現思路時鐘翻頁效果,用到四個Text組件,使用堆疊容器Stack。底層:用到兩個裁剪過后的Text上下顯示;頂層:也是用兩個裁剪后的Text做動畫效果,進行X軸角度旋轉。

3.1 裁剪Text

裁剪前:

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

裁剪后:

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

使用形狀裁剪屬性clip

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

裁剪Text下半部:從坐標(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放入堆疊容器

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

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


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


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


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

先頂層上部的動畫,上部旋轉角度從0到90停止,接下來執行頂層下部的動畫,下部旋轉角度從-90到0停止,停止完后重置初始狀態,上部旋轉角度 = 0、下部旋轉角度 = -90(代碼片段)

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


  /**
   * 啟動頂層文字下部動畫
   */
  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組件封裝

翻頁邏輯封裝成組件,提供給外部調用,根據外部傳入的雙向數據綁定:newValue,監聽數據變化,有變化則啟動翻頁動畫(代碼片段):

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


  /**
   * 監聽新值變化
   */
  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))


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


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

界面加載成功后,開啟循環定時器setInterval、間隔1秒更新時間。更改newValue的值,翻頁組件內部進行動畫翻頁。

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


@Entry
@Component
struct Index {
  // 小時-舊值
  @State oldHours: string = ''
  // 小時-新值
  @State newHours: string = ''
  // 分鐘-舊值
  @State oldMinutes: string = ''
  // 分鐘-新值
  @State newMinutes: string = ''
  // 秒數-舊值
  @State oldSeconds: string = ''
  // 秒數-新值
  @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() {
      // 翻頁組件-顯示小時
      FlipPage({ oldValue: this.oldHours, newValue: $newHours })
      // 冒號
      this.Colon()
      // 翻頁組件-顯示分鐘
      FlipPage({ oldValue: this.oldMinutes, newValue: $newMinutes })
      // 冒號
      this.Colon()
      // 翻頁組件-顯示秒數
      FlipPage({ oldValue: this.oldSeconds, newValue: $newSeconds })
    }
    .justifyContent(FlexAlign.Center)
    .width('100%')
    .height('100%')
    .onAppear(() => {
      // 開啟定時器
      this.initDate()
      setInterval(() => {
        this.updateDate()
      }, 1000)
    })
  }


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


  /**
   * 更新時間
   */
  updateDate() {
    let date = new Date()
    console.log(`${date.getHours()}${date.getMinutes()}${date.getSeconds()}秒`)
    // 當新值改變,才有動畫
    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)
    }
  }


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


原文標題:玩嗨OpenHarmony:基于OpenHarmony的ArkUI翻頁時鐘

文章出處:【微信公眾號:開源技術服務中心】歡迎添加關注!文章轉載請注明出處。


聲明:本文內容及配圖由入駐作者撰寫或者入駐合作網站授權轉載。文章觀點僅代表作者本人,不代表電子發燒友網立場。文章及其配圖僅供工程師學習之用,如有內容侵權或者其他違規問題,請聯系本站處理。 舉報投訴
  • 開源技術
    +關注

    關注

    0

    文章

    389

    瀏覽量

    8110
  • OpenHarmony
    +關注

    關注

    26

    文章

    3820

    瀏覽量

    18106

原文標題:玩嗨OpenHarmony:基于OpenHarmony的ArkUI翻頁時鐘

文章出處:【微信號:開源技術服務中心,微信公眾號:共熵服務中心】歡迎添加關注!文章轉載請注明出處。

收藏 人收藏

    評論

    相關推薦
    熱點推薦

    貢獻 OpenHarmony 庫關鍵配置

    # 貢獻 OpenHarmony 庫關鍵配置 #自研框架#ArkUI-X#三方框架#OpenHarmony#HarmonyOS ## 創建第三方庫 - 打開 DevEco Studio 創建一個
    發表于 05-28 13:46

    請問下,openharmony支持哪一款龍芯的開發板?有沒有開源的龍芯的openharmony源碼?

    想買個2k0300的開發板學習龍芯和openharmony,愣是沒有看到提供openharmony源碼的,也沒與看到開源的代碼。gitee上,openharmony的龍芯sig倉庫也是關閉的,有沒有人知道現在是什么情況?
    發表于 04-26 13:06

    2024年OpenHarmony社區年度激勵公示

    在過去一年里,OpenHarmony項目群技術指導委員會(TSC)向所有參與者致以最誠摯的感謝!大家的積極參與和鼎力支持推動了OpenHarmony社區的持續繁榮與高質量發展。OpenHarmony
    的頭像 發表于 04-21 18:17 ?228次閱讀

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

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

    觸覺智能亮相OpenHarmony人才生態大會2024

    11月27日,OpenHarmony人才生態大會2024在武漢隆重舉行,深圳觸覺智能科技受邀參與,并在OpenHarmony南向生態社區發展論壇分享發言!
    的頭像 發表于 11-28 18:27 ?538次閱讀
    觸覺智能亮相<b class='flag-5'>OpenHarmony</b>人才生態大會2024

    OpenHarmony首次亮相歐洲開源會議

    。OpenHarmony項目群技術指導委員會(TSC)主席陳海波受邀參加大會主論壇分享,由OpenHarmony 與Eclipse Oniro聯合籌劃的“Think Global, Code Local”分論壇
    的頭像 發表于 10-26 11:48 ?873次閱讀
    <b class='flag-5'>OpenHarmony</b>首次亮相歐洲開源會議

    第三屆OpenHarmony技術大會星光璀璨、致謝OpenHarmony社區貢獻者

    10月12日,在上海舉辦的第三屆OpenHarmony技術大會上,32家高校OpenHarmony技術俱樂部璀璨亮相,30家高校OpenHarmony開發者協會盛大啟幕。還分別致謝了年度星光TSG
    的頭像 發表于 10-21 14:10 ?467次閱讀

    第三屆OpenHarmony技術大會 “OpenHarmony開發者激勵計劃”授牌儀式圓滿舉行

    10月12日,以“技術引領筑生態,萬物智聯創未來”為主題的第三屆OpenHarmony技術大會隆重舉行,“OpenHarmony開發者激勵計劃”授牌儀式在大會期間同步進行。該計劃旨在增加
    的頭像 發表于 10-21 11:48 ?559次閱讀
    第三屆<b class='flag-5'>OpenHarmony</b>技術大會 “<b class='flag-5'>OpenHarmony</b>開發者激勵計劃”授牌儀式圓滿舉行

    OpenHarmony年度技術俱樂部、個人及活動評選結果公示

    2024年度技術俱樂部評選活動已經圓滿結束。在此,OpenHarmony項目群技術指導委員會(TSC)對所有參與者的積極參與和辛勤付出表示感謝。經過嚴格的評選和審核,現將名單予以公示: 評選
    的頭像 發表于 10-05 08:07 ?524次閱讀

    基于ArkTS語言的OpenHarmony APP應用開發:HelloOpenharmony

    1、程序簡介該程序是基于OpenHarmony標準系統編寫的UI應用類:HelloOpenHarmony。本案例是基于API9接口開發。本案例已在OpenHarmony凌蒙派-RK3568開發
    的頭像 發表于 09-15 08:09 ?747次閱讀
    基于ArkTS語言的<b class='flag-5'>OpenHarmony</b> APP應用開發:Hello<b class='flag-5'>Openharmony</b>

    基于ArkTS語言的OpenHarmony APP應用開發:簡易計數器

    1、程序簡介 該程序是基于OpenHarmony標準系統編寫的UI應用類:Sample Counter(簡單計數器)。 該程序設計1個按鈕和顯示框。當每次按下按鈕,則顯示框數字累加1。 本案
    發表于 09-14 13:38

    基于ArkTS語言的OpenHarmony APP應用開發:HelloOpenharmony

    1、程序簡介 該程序是基于OpenHarmony標準系統編寫的UI應用類:HelloOpenHarmony。 本案例是基于API 9接口開發。 本案例已在OpenHarmony凌蒙派-RK3568
    發表于 09-14 12:47

    河南大學OpenHarmony技術俱樂部正式揭牌成立

    8月30日,由OpenAtom OpenHarmony(以下簡稱“OpenHarmony”)項目群技術指導委員會與河南大學共同舉辦的“河南大學OpenHarmony技術俱樂部成立大會”在鄭州校區友蘭
    的頭像 發表于 09-03 16:12 ?655次閱讀
    河南大學<b class='flag-5'>OpenHarmony</b>技術俱樂部正式揭牌成立

    openharmony移植AT32F407編譯時錯誤

    openharmony上移植AT32F407,hb build后出現鏈接錯誤 [OHOS ERROR] /home/sven/openharmony/env_setup
    發表于 08-18 17:04

    OpenHarmony之開機優化

    一丶環境信息 源碼版本:OpenHarmony-4.1-Release 板子型號:dayu200(RK3568) 二丶Bootchart工具 在開機優化時,我們需要借助Bootchart工具,當前
    發表于 07-01 16:39