已知bug ScrollView的事件问题,有时候触到边界但却收不到对应的 “scroll-to-top” “scroll-to-bottom” “scroll-to-right” “scroll-to-left” 这四个事件 已通过植入如下代码修复
注意 此bug 目前cocos官方并未修复 所以理论上所有版本cocoscreator都有此bug
我的PR, https://github.com/cocos-creator/engine/pull/8937
cc.ScrollView.prototype['_scrollChildren'] = function (deltaMove) {
deltaMove = this._clampDelta(deltaMove);
var realMove = deltaMove;
var outOfBoundary = void 0;
if (this.elastic) {
outOfBoundary = this._getHowMuchOutOfBoundary();
realMove.x *= 0 === outOfBoundary.x ? 1 : .5;
realMove.y *= 0 === outOfBoundary.y ? 1 : .5;
}
if (!this.elastic) {
outOfBoundary = this._getHowMuchOutOfBoundary(realMove);
realMove = realMove.add(outOfBoundary);
}
let vertical_scrollEventType = "";
let horizontal_scrollEventType = "";
if (this.vertical) {
if (realMove.y > 0) {
var icBottomPos = this.content.y - this.content.anchorY * this.content.height;
icBottomPos + realMove.y > this._bottomBoundary && (vertical_scrollEventType = "scroll-to-bottom");
} else if (realMove.y < 0) {
var icTopPos = this.content.y - this.content.anchorY * this.content.height + this.content.height;
icTopPos + realMove.y <= this._topBoundary && (vertical_scrollEventType = "scroll-to-top");
}
}
if (this.horizontal) {
if (realMove.x < 0) {
var icRightPos = this.content.x - this.content.anchorX * this.content.width + this.content.width;
icRightPos + realMove.x <= this._rightBoundary && (horizontal_scrollEventType = "scroll-to-right");
} else if (realMove.x > 0) {
var icLeftPos = this.content.x - this.content.anchorX * this.content.width;
icLeftPos + realMove.x >= this._leftBoundary && (horizontal_scrollEventType = "scroll-to-left");
}
}
this._moveContent(realMove, false);
if (0 !== realMove.x || 0 !== realMove.y) {
if (!this._scrolling) {
this._scrolling = true;
this._dispatchEvent("scroll-began");
}
this._dispatchEvent("scrolling");
}
vertical_scrollEventType && this._dispatchEvent(vertical_scrollEventType);
horizontal_scrollEventType && this._dispatchEvent(horizontal_scrollEventType);
};