cc.Class({ extends: cc.Component, properties: { }, onLoad () { let scrollView = this.node.getComponent(cc.ScrollView); if (scrollView == null) { return; } let parentScrollView = this.getComponentInParent(cc.ScrollView); if (parentScrollView == null) { return; } this.parentScrollView = parentScrollView; this.oldOnTouchBegan = scrollView._onTouchBegan.bind(scrollView); this.oldOnTouchMoved = scrollView._onTouchMoved.bind(scrollView); this.oldOnTouchEnded = scrollView._onTouchEnded.bind(scrollView); scrollView._onTouchBegan = this.onTouchBegan.bind(this); scrollView._onTouchMoved = this.onTouchMoved.bind(this); scrollView._onTouchEnded = this.onTouchEnded.bind(this); }, onTouchBegan(event, captureListeners) { this.oldOnTouchBegan(event, captureListeners); this.parentScrollView._onTouchBegan(event, captureListeners); }, onTouchMoved(event, captureListeners) { this.oldOnTouchMoved(event, captureListeners); this.parentScrollView._onTouchMoved(event, captureListeners); }, onTouchEnded(event, captureListeners) { this.oldOnTouchEnded(event, captureListeners); this.parentScrollView._onTouchEnded(event, captureListeners); }, getComponentInParent(component) { let parent = this.node.parent; let result = null; while(parent != null) { let scrollView = parent.getComponent(component); if (scrollView != null) { result = scrollView; break; } parent = parent.parent; } return result; }, });