旋轉(zhuǎn)手勢(shì)事件

2024-01-22 16:49 更新

用于觸發(fā)旋轉(zhuǎn)手勢(shì)事件,觸發(fā)旋轉(zhuǎn)手勢(shì)的最少手指為2指,最大為5指,最小改變度數(shù)為1度。

說(shuō)明

從API Version 7開(kāi)始支持。后續(xù)版本如有新增內(nèi)容,則采用上角標(biāo)單獨(dú)標(biāo)記該內(nèi)容的起始版本。

接口

RotationGesture(value?: { fingers?: number, angle?: number })

參數(shù):

參數(shù)名稱(chēng)參數(shù)類(lèi)型必填參數(shù)描述
fingersnumber

觸發(fā)旋轉(zhuǎn)的最少手指數(shù), 最小為2指,最大為5指。

默認(rèn)值:2

anglenumber

觸發(fā)旋轉(zhuǎn)手勢(shì)的最小改變度數(shù),單位為deg。

默認(rèn)值:1

事件

名稱(chēng)功能描述
onActionStart(event:(event?: GestureEvent) => void)Rotation手勢(shì)識(shí)別成功回調(diào)。
onActionUpdate(event:(event?: GestureEvent) => void)Rotation手勢(shì)移動(dòng)過(guò)程中回調(diào)。
onActionEnd(event:(event?: GestureEvent) => void)Rotation手勢(shì)識(shí)別成功,手指抬起后觸發(fā)回調(diào)。
onActionCancel(event: () => void)Rotation手勢(shì)識(shí)別成功,接收到觸摸取消事件觸發(fā)回調(diào)。

示例

  1. // xxx.ets
  2. @Entry
  3. @Component
  4. struct RotationGestureExample {
  5. @State angle: number = 0
  6. @State rotateValue: number = 0
  7. build() {
  8. Column() {
  9. Column() {
  10. Text('RotationGesture angle:' + this.angle)
  11. }
  12. .height(200)
  13. .width(300)
  14. .padding(20)
  15. .border({ width: 3 })
  16. .margin(80)
  17. .rotate({ angle: this.angle })
  18. // 雙指旋轉(zhuǎn)觸發(fā)該手勢(shì)事件
  19. .gesture(
  20. RotationGesture()
  21. .onActionStart((event: GestureEvent) => {
  22. console.info('Rotation start')
  23. })
  24. .onActionUpdate((event: GestureEvent) => {
  25. this.angle = this.rotateValue + event.angle
  26. })
  27. .onActionEnd(() => {
  28. this.rotateValue = this.angle
  29. console.info('Rotation end')
  30. })
  31. )
  32. }.width('100%')
  33. }
  34. }

以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)