Cocos Creator Prevent touch event for parents

Hi all, I have a custom node where I use TOUCH_MOVE event, and this node is a child of ScrollViewComponent node. I do not need to scroll, when I am using touch inside my custom node.

I tried to do:

event.propagationStopped = true;

But looks like it do nothing. I still scroll when I touch move inside my node.

What version of Creator are you using? I can ask engineering to have a look.

Cocos version 3.4.0

You can rewrite the component to inherit a ScrollView component, like this.


import { _decorator, Component, Node, EventTouch, Button, ScrollView } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('ScollViewTest')
export class ScollViewTest extends ScrollView {
  protected _registerEvent () {
        this.node.on(Node.EventType.TOUCH_START, this._onTouchBegan, this, false);
        this.node.on(Node.EventType.TOUCH_MOVE, this._onTouchMoved, this, false);
        this.node.on(Node.EventType.TOUCH_END, this._onTouchEnded, this, false);
        this.node.on(Node.EventType.TOUCH_CANCEL, this._onTouchCancelled, this, false);
        this.node.on(Node.EventType.MOUSE_WHEEL, this._onMouseWheel, this, false);
    }
}

Thanks, But I want my own component for this without extends. I just remember somehow I can interrupt input to go higher, but don’t know how

That was the way it used to be in the old version, but it’s no longer valid in the current version. use ‘propagationStopped’ This does not work on the scrollview component, as the event dispatch is already being listened to by the scrollview component before it is dispatched

But when I create default scroll view inside another scroll view, my inner scroll view prevent touch events to the higher scroll view, how this works in this way?

image
This is because this property is used internally to determine when sliding

So in my case, the solution is only to inherit from ScrollView component? Thanks.

This is the easiest and most effective way or you can try to remove the capture within the function that handles it

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.