mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-01 15:52:40 +08:00
Merge pull request #884 from zilongshanren/fix-scrollview-scroll-issues
hidden scrollbar when content size smaller than scrollview
This commit is contained in:
@@ -327,11 +327,16 @@ var Scrollbar = cc.Class({
|
||||
}
|
||||
},
|
||||
|
||||
reset: function() {
|
||||
hide: function() {
|
||||
this._autoHideRemainingTime = 0;
|
||||
this._setOpacity(0);
|
||||
},
|
||||
|
||||
show: function() {
|
||||
this._autoHideRemainingTime = 0;
|
||||
this._setOpacity(this._opacity);
|
||||
},
|
||||
|
||||
update: function(dt) {
|
||||
this._processAutoHide(dt);
|
||||
}
|
||||
|
||||
@@ -527,7 +527,6 @@ var ScrollView = cc.Class({
|
||||
* @return {Vec2} - A Vec2 value indicate the current scroll offset.
|
||||
*/
|
||||
getScrollOffset: function() {
|
||||
var maxScrollOffset = this.getMaxScrollOffset();
|
||||
var topDelta = this._topBoundary - this._getContentTopBoundary();
|
||||
var leftDeta = this._getContentLeftBoundary() - this._leftBoundary;
|
||||
|
||||
@@ -769,6 +768,45 @@ var ScrollView = cc.Class({
|
||||
var topRightPosition = this._convertToContentParentSpace(cc.p(scrollViewSize.width, scrollViewSize.height));
|
||||
this._rightBoundary = topRightPosition.x;
|
||||
this._topBoundary = topRightPosition.y;
|
||||
|
||||
var contentSize = this.content.getContentSize();
|
||||
|
||||
var bottomDeta = this._getContentBottomBoundary() - this._bottomBoundary;
|
||||
bottomDeta = -bottomDeta;
|
||||
var moveDelta = cc.p(0, 0);
|
||||
var totalScrollDelta = 0;
|
||||
|
||||
var leftDeta = this._getContentLeftBoundary() - this._leftBoundary;
|
||||
leftDeta = -leftDeta;
|
||||
|
||||
if (contentSize.height < scrollViewSize.height) {
|
||||
totalScrollDelta = contentSize.height - scrollViewSize.height;
|
||||
moveDelta.y = bottomDeta - totalScrollDelta;
|
||||
|
||||
if (this.verticalScrollBar) {
|
||||
this.verticalScrollBar.hide();
|
||||
}
|
||||
} else {
|
||||
if (this.verticalScrollBar) {
|
||||
this.verticalScrollBar.show();
|
||||
}
|
||||
}
|
||||
|
||||
if (contentSize.width < scrollViewSize.width) {
|
||||
totalScrollDelta = contentSize.width - scrollViewSize.width;
|
||||
moveDelta.x = leftDeta;
|
||||
|
||||
if (this.horizontalScrollBar) {
|
||||
this.horizontalScrollBar.hide();
|
||||
}
|
||||
|
||||
} else {
|
||||
if (this.horizontalScrollBar) {
|
||||
this.horizontalScrollBar.show();
|
||||
}
|
||||
}
|
||||
|
||||
this._moveContent(moveDelta);
|
||||
}
|
||||
},
|
||||
|
||||
@@ -891,7 +929,6 @@ var ScrollView = cc.Class({
|
||||
|
||||
_handlePressLogic: function() {
|
||||
this._autoScrolling = false;
|
||||
this._calculateBoundary();
|
||||
|
||||
this._touchMovePreviousTimestamp = getTimeInMilliseconds();
|
||||
this._touchMoveDisplacements = [];
|
||||
@@ -1229,6 +1266,9 @@ var ScrollView = cc.Class({
|
||||
if (!CC_EDITOR) {
|
||||
this._registerEvent();
|
||||
this.node.on('size-changed', this._calculateBoundary, this);
|
||||
if(this.content) {
|
||||
this.content.on('size-changed', this._calculateBoundary, this);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -1238,16 +1278,23 @@ var ScrollView = cc.Class({
|
||||
|
||||
onDestroy: function() {
|
||||
this.node.off('size-changed', this._calculateBoundary, this);
|
||||
if(this.content) {
|
||||
this.content.off('size-changed', this._calculateBoundary, this);
|
||||
}
|
||||
},
|
||||
|
||||
onDisable: function() {
|
||||
_hideScrollbar: function () {
|
||||
if (this.horizontalScrollBar) {
|
||||
this.horizontalScrollBar.reset();
|
||||
this.horizontalScrollBar.hide();
|
||||
}
|
||||
|
||||
if (this.verticalScrollBar) {
|
||||
this.verticalScrollBar.reset();
|
||||
this.verticalScrollBar.hide();
|
||||
}
|
||||
},
|
||||
|
||||
onDisable: function() {
|
||||
this._hideScrollbar();
|
||||
this._autoScrolling = false;
|
||||
this._autoScrollAccumulatedTime = this._autoScrollTotalTime;
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user