[开源] 36行代码实现一个ScrollView/PageView嵌套辅助组件

楼主好强,已经用上了,谢谢

能用,谢谢楼主
3.x的要稍作修改
import { _decorator, Component, EventTouch, Node } from ‘cc’;

class EventTouchNew extends EventTouch {

// simulate?: boolean

sham?: boolean

}

const { ccclass, property } = _decorator;

@ccclass(‘ViewGroupNesting’)

export default class ViewGroupNesting extends Component {

private events: EventTouch[] = [];

onLoad() {

    this.node.on(Node.EventType.TOUCH_START, this.onTouchHandle, this, true);

    this.node.on(Node.EventType.TOUCH_MOVE, this.onTouchHandle, this, true);

    this.node.on(Node.EventType.TOUCH_END, this.onTouchHandle, this, true);

    this.node.on(Node.EventType.TOUCH_CANCEL, this.onTouchHandle, this, true);

}

private onTouchHandle(event: EventTouchNew) {

    if (event.sham || event.simulate || event.target === this.node) return;

    let cancelEvent: EventTouchNew = new EventTouchNew(event.getTouches(), event.bubbles, event.getType());

    cancelEvent.type = event.type;

    cancelEvent.touch = event.touch;

    cancelEvent.sham = true;

    this.events.push(cancelEvent);

}

update() {

    if (this.events.length === 0) return;

    for (let index = 0; index < this.events.length; index++) {

        this.node.dispatchEvent(this.events[index]);

    }

    this.events.length = 0;

}

}

2赞

你好,这个如何控制外层的Pageview左右移动时,不时同时也可以移动内层的scrollview上下移动?

mark.

mark!

3.8.1版本中使用,只要嵌套的列表中存在“按钮”,“在按钮上拖动,就会报错,且会影响整个游戏不正常”

mark!!!

1赞

牛啊 牛啊,用上了

MARK KKKK~~~