組合手勢
手勢識別組合,即多種手勢組合為復(fù)合手勢,支持連續(xù)識別、并行識別和互斥識別。
說明:
開發(fā)前請熟悉鴻蒙開發(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è)置組合手勢識別模式。 默認(rèn)值:GestureMode.Sequence |
gesture | [TapGesture] | [LongPressGesture] | [PanGesture] |
GestureMode枚舉說明
名稱 | 描述 |
---|---|
Sequence | 順序識別,按照手勢的注冊順序識別手勢,直到所有手勢識別成功。當(dāng)有一個(gè)手勢識別失敗時(shí),所有手勢識別失敗。 順序識別手勢組僅有最后一個(gè)手勢可以響應(yīng)onActionEnd。 |
Parallel | 并發(fā)識別,注冊的手勢同時(shí)識別,直到所有手勢識別結(jié)束,手勢識別互相不影響。 |
Exclusive | 互斥識別,注冊的手勢同時(shí)識別,若有一個(gè)手勢識別成功,則結(jié)束手勢識別。 |
事件
名稱 | 功能描述 |
---|---|
onCancel(event: () => void) | 順序組合手勢(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(
// 以下組合手勢為順序識別,當(dāng)長按手勢事件未正常觸發(fā)時(shí)則不會觸發(fā)拖動(dòng)手勢事件
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ā)長按事件:
按順序首先觸發(fā)長按事件,長按事件識別結(jié)束之后,其次觸發(fā)拖動(dòng)事件,向右下方拖動(dòng):
審核編輯 黃宇
-
鴻蒙
+關(guān)注
關(guān)注
60文章
2618瀏覽量
44038
發(fā)布評論請先 登錄
HarmonyOS/OpenHarmony應(yīng)用開發(fā)-ArkTS的聲明式開發(fā)范式
鴻蒙ArkTS聲明式開發(fā):跨平臺支持列表【組件快捷鍵事件】

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

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

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

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

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

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

評論