偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

如何使用彈簧動(dòng)畫曲線

系統(tǒng) OpenHarmony
OpenHarmony提供了三種彈簧動(dòng)畫曲線用來實(shí)現(xiàn)彈性效果,本例將為大家介紹這三種曲線的用法。

想了解更多關(guān)于開源的內(nèi)容,請(qǐng)?jiān)L問:

51CTO 開源基礎(chǔ)軟件社區(qū)

https://ost.51cto.com

場(chǎng)景說明

在動(dòng)畫開發(fā)場(chǎng)景中,經(jīng)常用到彈性效果,尤其在拖拽某個(gè)對(duì)象時(shí)經(jīng)常伴隨彈性動(dòng)效。OpenHarmony提供了三種彈簧動(dòng)畫曲線用來實(shí)現(xiàn)彈性效果,本例將為大家介紹這三種曲線的用法。

效果呈現(xiàn)

本例最終效果如下:

如何使用彈簧動(dòng)畫曲線-開源基礎(chǔ)軟件社區(qū)

運(yùn)行環(huán)境

本例基于以下環(huán)境開發(fā),開發(fā)者也可以基于其他適配的版本進(jìn)行開發(fā):

  • IDE: DevEco Studio 3.1 Beta2
  • SDK: Ohos_sdk_public 3.2.11.9(API Version 9 Release)

實(shí)現(xiàn)思路

本例主要用到以下三種彈簧動(dòng)畫曲線:

  • curves.springCurve:通過設(shè)置彈簧的初始速度、質(zhì)量、剛度和阻尼來控制彈簧動(dòng)畫的效果。對(duì)應(yīng)本例中springCurve按鈕觸發(fā)的動(dòng)畫。
  • curves.springMotion:通過設(shè)置彈簧震動(dòng)時(shí)間和阻尼來控制彈簧動(dòng)畫的效果。對(duì)應(yīng)本例中springMotion按鈕觸發(fā)的動(dòng)畫。
  • curves.responsiveSpringMotion:構(gòu)造彈性跟手動(dòng)畫曲線對(duì)象,是springMotion的一種特例,僅默認(rèn)參數(shù)不同,可與springMotion混合使用。用來實(shí)現(xiàn)拖拽動(dòng)畫。

開發(fā)步驟

搭建UI框架。
樣例中有兩個(gè)按鈕,一個(gè)圖片。內(nèi)容整體縱向分布,兩個(gè)按鈕橫向分布。縱向布局可以采用Column組件,橫向布局可以采用Row組件。代碼如下:

@Entry
@Component
struct ImageComponent {
  build() {
    Column() {
      Row() {
        Button('springCurve')
          .margin({right:10})
          .fontSize(20)
          .backgroundColor('#18183C')
        Button('springMotion')
          .fontSize(20)
          .backgroundColor('#18183C')
      }
      .margin({top:30})

      Image($r("app.media.contact2"))
        .width(100)
        .height(100)
    }.width("100%").height("100%").backgroundColor('#A4AE77')
  }
}

為springCurve按鈕添加curves.springCurve的曲線動(dòng)畫。

...
// 定義狀態(tài)變量translateY,用來控制笑臉圖像的位移
@State translateY: number = 0
	...
    Button('springCurve')
      .margin({right:10})
      .fontSize(20)
      .backgroundColor('#18183C')
      // 綁定點(diǎn)擊事件
      .onClick(() => {
        // 在點(diǎn)擊事件中添加顯示動(dòng)畫
        animateTo({
          duration: 2000,
          // 設(shè)定curves.springCurve為動(dòng)畫曲線
          curve: curves.springCurve(100, 10, 80, 10)
        },
        () => {
          // 改變translateY的值,使笑臉圖像發(fā)生位移
          this.translateY = -20
        })
        this.translateY = 0
      })
	...
    Image($r("app.media.contact2"))
      .width(100)
      .height(100)
      // 為笑臉圖像添加位移屬性,以translateY為參數(shù)
      .translate({ y: this.translateY })
	...

效果如下:

如何使用彈簧動(dòng)畫曲線-開源基礎(chǔ)軟件社區(qū)

為springMotion按鈕添加curves.springMotion曲線動(dòng)畫。
這里通過position屬性控制springMotion按鈕的移動(dòng),當(dāng)然開發(fā)者也可以繼續(xù)選擇使用translate屬性。

...
  // 定義狀態(tài)變量translateY,用來控制笑臉圖像的位置變化
  @State imgPos: {
    x: number,
    y: number
  } = { x: 125, y: 400 }
        ...
        Button('springMotion')
          .fontSize(20)
          .backgroundColor('#18183C')
          // 綁定點(diǎn)擊事件
          .onClick(() => {
          // 在點(diǎn)擊事件中添加顯示動(dòng)畫
          animateTo({
            duration: 15,
            //設(shè)定curves.springMotion為動(dòng)畫曲線
            curve: curves.springMotion(0.5, 0.5),
            onFinish: () => {
              animateTo({ duration: 500,
                curve: curves.springMotion(0.5, 0.5), }, () => {
                // 動(dòng)畫結(jié)束時(shí)笑臉圖像位置還原
                this.imgPos = { x: 125, y: 400 }
              })
            }
          }, () => {
            // 改變笑臉圖像位置,y軸位置由400,變?yōu)?50
            this.imgPos = { x: 125, y: 150 }
          })
        })
      ...
      Image($r("app.media.contact2"))
        .width(100)
        .height(100)
        .translate({ y: this.translateY })
        // 為笑臉圖像添加位置屬性,以imgPos為參數(shù)
        .position(this.imgPos)
     ...

效果如下:

如何使用彈簧動(dòng)畫曲線-開源基礎(chǔ)軟件社區(qū)

使用curves.responsiveSpringMotion為笑臉圖像添加拖拽動(dòng)畫。

...
      Image($r("app.media.contact2"))
        .width(100)
        .height(100)
        .translate({ y: this.translateY })
        .position(this.imgPos)
        // 綁定觸摸事件
        .onTouch((event: TouchEvent) => {
          // 當(dāng)觸摸放開時(shí),笑臉圖像位置還原
          if (event.type == TouchType.Up) {
            animateTo({
              duration: 50,
              delay: 0,
              curve: curves.springMotion(),
              onFinish: () => {
              }
            }, () => {
              this.imgPos = { x: 125, y: 400 }
            })
          } else {
            // 觸摸過程中觸發(fā)跟手動(dòng)畫
            animateTo({
              duration: 50,
              delay: 0,
              //設(shè)定跟手動(dòng)畫曲線
              curve: curves.responsiveSpringMotion(),
              onFinish: () => {
              }
            }, () => {
              // 根據(jù)觸點(diǎn)位置改變笑臉圖像位置,從而實(shí)現(xiàn)跟手動(dòng)畫
              this.imgPos = {
                x: event.touches[0].screenX - 100 / 2,
                y: event.touches[0].screenY - 100 / 2
              }
            })
          }
        })
...

效果如下:

如何使用彈簧動(dòng)畫曲線-開源基礎(chǔ)軟件社區(qū)

完整代碼

本例完整代碼如下:

import curves from '@ohos.curves';

@Entry
@Component
struct ImageComponent {
  // 定義狀態(tài)變量translateY,用來控制笑臉圖像的位移
  @State translateY: number = 0
  // 定義狀態(tài)變量translateY,用來控制笑臉圖像的位置變化
  @State imgPos: {
    x: number,
    y: number
  } = { x: 125, y: 400 }

  build() {
    Column() {
      Row() {
        Button('springCurve')
          .margin({right:10})
          .fontSize(20)
          .backgroundColor('#18183C')
          // 綁定點(diǎn)擊事件
          .onClick(() => {
            // 在點(diǎn)擊事件中添加顯示動(dòng)畫
            animateTo({
              duration: 2000,
              // 設(shè)定curves.springCurve為動(dòng)畫曲線
              curve: curves.springCurve(100, 10, 80, 10)
            },
            () => {
              // 改變translateY的值,使笑臉圖像發(fā)生位移
              this.translateY = -20
            })
            this.translateY = 0
          })
        Button('springMotion')
          .fontSize(20)
          .backgroundColor('#18183C')
          // 綁定點(diǎn)擊事件
          .onClick(() => {
            // 在點(diǎn)擊事件中添加顯示動(dòng)畫
            animateTo({
              duration: 15,
              //設(shè)定curves.springMotion為動(dòng)畫曲線
              curve: curves.springMotion(0.5, 0.5),
              onFinish: () => {
                animateTo({ duration: 500,
                  curve: curves.springMotion(0.5, 0.5), }, () => {
                  // 動(dòng)畫結(jié)束時(shí)笑臉圖像位置還原
                  this.imgPos = { x: 125, y: 400 }
                })
              }
            }, () => {
              // 改變笑臉圖像位置,y軸位置由400,變?yōu)?50
              this.imgPos = { x: 125, y: 150 }
            })
        })
      }
      .margin({top:30})

      Image($r("app.media.contact2"))
        .width(100)
        .height(100)
        // 為笑臉圖像添加位移屬性,以translateY為參數(shù)
        .translate({ y: this.translateY })
        // 為笑臉圖像添加位置屬性,以imgPos為參數(shù)
        .position(this.imgPos)
        // 綁定觸摸事件
        .onTouch((event: TouchEvent) => {
          // 當(dāng)觸摸放開時(shí),笑臉圖像位置還原
          if (event.type == TouchType.Up) {
            animateTo({
              duration: 50,
              delay: 0,
              curve: curves.springMotion(),
              onFinish: () => {
              }
            }, () => {
              this.imgPos = { x: 125, y: 400 }
            })
          } else {
            // 觸摸過程中觸發(fā)跟手動(dòng)畫,同樣通過animateTo實(shí)現(xiàn)動(dòng)畫效果
            animateTo({
              duration: 50,
              delay: 0,
              //設(shè)定跟手動(dòng)畫曲線
              curve: curves.responsiveSpringMotion(),
              onFinish: () => {
              }
            }, () => {
              // 根據(jù)觸點(diǎn)位置改變笑臉圖像位置,從而實(shí)現(xiàn)跟手動(dòng)畫
              this.imgPos = {
                x: event.touches[0].screenX - 100 / 2,
                y: event.touches[0].screenY - 100 / 2
              }
            })
          }
        })
    }.width("100%").height("100%").backgroundColor('#A4AE77')
  }
}

想了解更多關(guān)于開源的內(nèi)容,請(qǐng)?jiān)L問:

51CTO 開源基礎(chǔ)軟件社區(qū)

https://ost.51cto.com

責(zé)任編輯:jianghua 來源: 51CTO 開源基礎(chǔ)軟件社區(qū)
相關(guān)推薦

2021-06-01 09:27:52

視頻動(dòng)畫Remotion

2010-12-01 11:03:20

職場(chǎng)

2009-09-22 12:59:58

ibmdwDojo

2022-11-23 08:17:18

CSS動(dòng)畫貝塞爾

2021-07-27 05:53:00

Chrome瀏覽器KPI

2017-04-27 20:30:33

Android動(dòng)畫技巧

2017-03-28 13:00:10

LinuxGifineGIF動(dòng)畫

2014-04-08 17:35:24

iOS 7彈簧式列表

2023-06-05 09:28:32

CSS漸變

2021-12-15 19:22:38

原理View動(dòng)畫

2021-12-20 20:30:48

鴻蒙HarmonyOS應(yīng)用

2020-07-09 13:10:42

GIMP曲線文本應(yīng)用

2023-09-13 14:45:14

性能測(cè)試開發(fā)

2014-05-30 09:44:08

Android折紙動(dòng)畫

2021-05-11 08:19:00

CSS 文字動(dòng)畫技巧

2021-02-21 08:12:24

SVG線條動(dòng)畫Web動(dòng)畫

2012-12-24 13:38:01

iOSUIView

2018-10-10 09:00:00

前端框架Angular

2021-01-04 11:10:14

鴻蒙HarmonyOSCanvas

2023-04-27 09:55:09

分類器ROC曲線混淆矩陣
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)