組合手勢(shì)
手勢(shì)識(shí)別組合,即多種手勢(shì)組合為復(fù)合手勢(shì),支持連續(xù)識(shí)別、并行識(shí)別和互斥識(shí)別。
說(shuō)明:
開發(fā)前請(qǐng)熟悉鴻蒙開發(fā)指導(dǎo)文檔 :[gitee.com/li-shizhen-skin/harmony-os/blob/master/README.md
]
從API Version 7開始支持。后續(xù)版本如有新增內(nèi)容,則采用上角標(biāo)單獨(dú)標(biāo)記該內(nèi)容的起始版本。
接口
GestureGroup(mode: GestureMode, ...gesture: GestureType[])
參數(shù):
參數(shù)名 | 參數(shù)類型 | 必填 | 參數(shù)描述 |
---|---|---|---|
mode | [GestureMode] | 是 | 設(shè)置組合手勢(shì)識(shí)別模式。 默認(rèn)值:GestureMode.Sequence |
gesture | [TapGesture] | [LongPressGesture] | [PanGesture] |
GestureMode枚舉說(shuō)明
名稱 | 描述 |
---|---|
Sequence | 順序識(shí)別,按照手勢(shì)的注冊(cè)順序識(shí)別手勢(shì),直到所有手勢(shì)識(shí)別成功。當(dāng)有一個(gè)手勢(shì)識(shí)別失敗時(shí),所有手勢(shì)識(shí)別失敗。 順序識(shí)別手勢(shì)組僅有最后一個(gè)手勢(shì)可以響應(yīng)onActionEnd。 |
Parallel | 并發(fā)識(shí)別,注冊(cè)的手勢(shì)同時(shí)識(shí)別,直到所有手勢(shì)識(shí)別結(jié)束,手勢(shì)識(shí)別互相不影響。 |
Exclusive | 互斥識(shí)別,注冊(cè)的手勢(shì)同時(shí)識(shí)別,若有一個(gè)手勢(shì)識(shí)別成功,則結(jié)束手勢(shì)識(shí)別。 |
事件
名稱 | 功能描述 |
---|---|
onCancel(event: () => void) | 順序組合手勢(shì)(GestureMode.Sequence)取消后觸發(fā)回調(diào)。 |
示例
// xxx.ets
@Entry
@Component
struct GestureGroupExample {
@State count: number = 0
@State offsetX: number = 0
@State offsetY: number = 0
@State positionX: number = 0
@State positionY: number = 0
@State borderStyles: BorderStyle = BorderStyle.Solid
build() {
Column() {
Text('sequence gesturen' + 'LongPress onAction:' + this.count + 'nPanGesture offset:nX: ' + this.offsetX + 'n' + 'Y: ' + this.offsetY)
.fontSize(15)
}
.translate({ x: this.offsetX, y: this.offsetY, z: 0 })
.height(150)
.width(200)
.padding(20)
.margin(20)
.border({ width: 3, style: this.borderStyles })
.gesture(
// 以下組合手勢(shì)為順序識(shí)別,當(dāng)長(zhǎng)按手勢(shì)事件未正常觸發(fā)時(shí)則不會(huì)觸發(fā)拖動(dòng)手勢(shì)事件
GestureGroup(GestureMode.Sequence,
LongPressGesture({ repeat: true })
.onAction((event?: GestureEvent) = > {
if (event && event.repeat) {
this.count++
}
console.info('LongPress onAction')
}),
PanGesture()
.onActionStart(() = > {
this.borderStyles = BorderStyle.Dashed
console.info('pan start')
})
.onActionUpdate((event?: GestureEvent) = > {
if (event) {
this.offsetX = this.positionX + event.offsetX
this.offsetY = this.positionY + event.offsetY
}
console.info('pan update')
})
.onActionEnd(() = > {
this.positionX = this.offsetX
this.positionY = this.offsetY
this.borderStyles = BorderStyle.Solid
console.info('pan end')
})
)
.onCancel(() = > {
console.info('sequence gesture canceled')
})
)
}
}
`HarmonyOS與OpenHarmony鴻蒙文檔籽料:mau123789是v直接拿`
示意圖:
按順序首先觸發(fā)長(zhǎng)按事件:
按順序首先觸發(fā)長(zhǎng)按事件,長(zhǎng)按事件識(shí)別結(jié)束之后,其次觸發(fā)拖動(dòng)事件,向右下方拖動(dòng):
審核編輯 黃宇
-
鴻蒙
+關(guān)注
關(guān)注
59文章
2508瀏覽量
43769
發(fā)布評(píng)論請(qǐng)先 登錄
HarmonyOS/OpenHarmony應(yīng)用開發(fā)-ArkTS的聲明式開發(fā)范式
鴻蒙ArkTS聲明式開發(fā):跨平臺(tái)支持列表【組件快捷鍵事件】

鴻蒙ArkTS聲明式開發(fā):跨平臺(tái)支持列表【顯隱控制】 通用屬性

鴻蒙ArkTS聲明式開發(fā):跨平臺(tái)支持列表【形狀裁剪】 通用屬性

鴻蒙ArkTS聲明式開發(fā):跨平臺(tái)支持列表【菜單控制】 通用屬性

鴻蒙ArkTS聲明式開發(fā):跨平臺(tái)支持列表【多態(tài)樣式】 通用屬性

鴻蒙ArkTS聲明式開發(fā):跨平臺(tái)支持列表LongPressGesture之基礎(chǔ)手勢(shì)

鴻蒙ArkTS聲明式開發(fā):跨平臺(tái)支持列表PanGesture之基礎(chǔ)手勢(shì)

鴻蒙ArkTS聲明式開發(fā):跨平臺(tái)支持列表PinchGesture之基礎(chǔ)手勢(shì)

鴻蒙ArkTS聲明式開發(fā):跨平臺(tái)支持列表RotationGesture之基礎(chǔ)手勢(shì)

評(píng)論