觸發(fā)捏合手勢(shì)

2024-01-22 16:49 更新

用于觸發(fā)捏合手勢(shì),觸發(fā)捏合手勢(shì)的最少手指為2指,最大為5指,最小識(shí)別距離為5vp。

說(shuō)明

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

接口

PinchGesture(value?: { fingers?: number, distance?: number })

參數(shù):

參數(shù)名稱(chēng)

參數(shù)類(lèi)型

必填

參數(shù)描述

fingers

number

觸發(fā)捏合的最少手指數(shù), 最小為2指,最大為5指。

默認(rèn)值:2

distance

number

最小識(shí)別距離,單位為vp。

默認(rèn)值:5

事件

名稱(chēng)

功能描述

onActionStart(event:(event?: GestureEvent) => void)

Pinch手勢(shì)識(shí)別成功回調(diào)。

onActionUpdate(event:(event?: GestureEvent) => void)

Pinch手勢(shì)移動(dòng)過(guò)程中回調(diào)。

onActionEnd(event:(event?: GestureEvent) => void)

Pinch手勢(shì)識(shí)別成功,手指抬起后觸發(fā)回調(diào)。

onActionCancel(event: () => void)

Pinch手勢(shì)識(shí)別成功,接收到觸摸取消事件觸發(fā)回調(diào)。

示例

  1. // xxx.ets
  2. @Entry
  3. @Component
  4. struct PinchGestureExample {
  5. @State scaleValue: number = 1
  6. @State pinchValue: number = 1
  7. @State pinchX: number = 0
  8. @State pinchY: number = 0
  9. build() {
  10. Column() {
  11. Column() {
  12. Text('PinchGesture scale:\n' + this.scaleValue)
  13. Text('PinchGesture center:\n(' + this.pinchX + ',' + this.pinchY + ')')
  14. }
  15. .height(200)
  16. .width(300)
  17. .padding(20)
  18. .border({ width: 3 })
  19. .margin({ top: 100 })
  20. .scale({ x: this.scaleValue, y: this.scaleValue, z: 1 })
  21. // 三指捏合觸發(fā)該手勢(shì)事件
  22. .gesture(
  23. PinchGesture({ fingers: 3 })
  24. .onActionStart((event: GestureEvent) => {
  25. console.info('Pinch start')
  26. })
  27. .onActionUpdate((event: GestureEvent) => {
  28. this.scaleValue = this.pinchValue * event.scale
  29. this.pinchX = event.pinchCenterX
  30. this.pinchY = event.pinchCenterY
  31. })
  32. .onActionEnd(() => {
  33. this.pinchValue = this.scaleValue
  34. console.info('Pinch end')
  35. })
  36. )
  37. }.width('100%')
  38. }
  39. }

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

掃描二維碼

下載編程獅App

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

編程獅公眾號(hào)