HarmonyOS开发者版主1|
ArkUI (方舟UI框架)
UI
HarmonyOS 5
HarmonyOS 使用gestureModifier时,如何同时绑定两个手势,比如同时绑定pan手势和pinch手势,当手指触摸到屏幕时,两个手势都可以响应?(API12+)
HarmonyOS 使用gestureModifier时,如何同时绑定两个手势,比如同时绑定pan手势和pinch手势,当手指触摸到屏幕时,两个手势都可以响应?(API12+)
1
浏览44 发布于2026-04-02 11:25未知归属地
全部评论
最多点赞
最新发布
最早发布

可以通过创建手势组来实现。
参考demo:
收起
自动换行
深色代码主题
复制
class MyButtonModifier5 implements GestureModifier {
supportDoubleTap: boolean = true;
applyGesture(event: UIGestureEvent): void {
if (this.supportDoubleTap) {
event.addGesture(
new PanGestureHandler({ fingers: 1, direction: PanDirection.All, distance: 5})
.onActionStart((event: GestureEvent) => {
console.log("zcb button pan " + JSON.stringify(event));
})
.tag("10"),
)
event.addGesture(
new PanGestureHandler({ fingers: 1, direction: PanDirection.All, distance: 5})
.onActionStart((event: GestureEvent) => {
console.log("zcb button pan " + JSON.stringify(event));
})
.tag("11"),
)
event.addGesture(
new PanGestureHandler({ fingers: 1, direction: PanDirection.All, distance: 5})
.onActionStart((event: GestureEvent) => {
console.log("zcb button pan " + JSON.stringify(event));
})
.tag("aaa"),
)
event.addGesture(
new GestureGroupHandler({ mode: GestureMode.Parallel, gestures: [
new GestureGroupHandler({ mode: GestureMode.Exclusive, gestures: [
new GestureGroupHandler({ mode: GestureMode.Sequence, gestures: [
new LongPressGestureHandler()
.onAction((event: GestureEvent) => {
console.log("zcb button long press");
})
.tag("aaa"),
new PanGestureHandler()
.onActionStart((event: GestureEvent) => {
console.log("zcb button pan");
})
.tag("5"),
]}).tag("3"),
new GestureGroupHandler({ mode: GestureMode.Exclusive, gestures: [
new TapGestureHandler({ count: 1, fingers: 1 })
.onAction((event: GestureEvent) => {
console.log("zcb button click Click");
})
.tag("aaa"),
new TapGestureHandler({ count: 2, fingers: 1 })
.onAction((event: GestureEvent) => {
console.log("zcb button double Click");
})
.tag("6"),
]}).tag("aaa"),
new TapGestureHandler({ count: 1, fingers: 1 })
.onAction((event: GestureEvent) => {
console.log("zcb button click Click");
})
.tag("aaa"),
new TapGestureHandler({ count: 2, fingers: 1 })
.onAction((event: GestureEvent) => {
console.log("zcb button double Click");
})
.tag("7"),
]}).onCancel(()=>{
console.log("GestureGroupHandler onCancel");
})
.tag("2"),
new TapGestureHandler({ count: 1, fingers: 1 })
.onAction((event: GestureEvent) => {
console.log("zcb button click Click");
})
.tag("8"),
new TapGestureHandler({ count: 2, fingers: 1 })
.onAction((event: GestureEvent) => {
console.log("zcb button double Click");
})
.tag("9"),
]})
.tag("1")
.onCancel(()=>{
console.log("GestureGroupHandler onCancel");
})
)
event.removeGestureByTag("aaa");
}
}
}
@Entry
@Component
struct CompositeSceneTest {
@State message: string = 'Hello World';
@State modifier: MyButtonModifier5 = new MyButtonModifier5();
build() {
Row() {
Column() {
Column()
.gestureModifier(this.modifier)
.width(500)
.height(500)
.backgroundColor(Color.Blue)
}
.width('100%')
}
.height('100%')
}
}
展开全部 
1楼回复于2026-04-02 11:25 未知归属地
写回答
所见即所得编辑器, editor1
新增插入模板功能
一键使用模板,快速填写内容,轻松发帖~
知道了
- 为了保障您的信息安全,请勿上传您的敏感个人信息(如您的密码等信息)和您的敏感资产信息(如关键源代码、签名私钥、调试安装包、业务日志等信息),且您需自行承担由此产生的信息泄露等安全风险。
- 如您发布的内容为转载内容,请注明内容来源。
我要提问题
相关推荐
换一批
1
HarmonyOS 如何实现手势绘制图形?(API12+)
2
HarmonyOS SideBarContainer手势滑动冲突怎么解决?(API12+)
3
HarmonyOS 组件上已经通过bindContextMenu绑定的菜单怎么取消掉绑定(API12+)
4
HarmonyOS 边缘手势是哪个API控制的 (API12+)
5
HarmonyOS 双指横向拖动会被识别成pan手势,双指上下拖动会被识别成pinch手势,不合理(API12+)
6
HarmonyOS 动态修改GestureGroup里面的手势 (API12+)
7
HarmonyOS 给组件同时绑定手势和onclick事件,手势不生效,都跳转到click事件了(API12+)
8
HarmonyOS 折叠屏PC既支持键鼠又支持触控手势,要区分两种输入事件,分别对应两种交互方式,要怎么实现?(API12+)
了解社区公约,与您携手共创和谐专业的开发者社区。




































苏公安网备 32011402010933号