关于pageView组件的问题

黄钰FTD
Thu, 24 Jan 2019 10:06:15 +0000

onLoad: function() {
this.pageViewComp = this.node.getComponent(cc.PageView);
this.setCurrentShowPage(1);
this._setAutoScroll();
this.pageViewComp.node.on(“scroll-ended”, function() {
let currentIndex = this.pageViewComp.getCurrentPageIndex();
if (currentIndex == (this.pageViewComp._pages.length - 1)) {
let firstPage = this.pageViewComp._pages[0];
this.pageViewComp.removePage(firstPage);
this.pageViewComp.addPage(firstPage);
}
if (currentIndex == 0) {
let lastPage = this.pageViewComp._pages[this.pageViewComp._pages.length - 1];
this.pageViewComp.removePage(lastPage);
this.pageViewComp.insertPage(lastPage, 0);
this.setCurrentShowPage(1);
}
this._setAutoScroll();
}, this);
},
_setAutoScroll: function() {
this.pageViewComp.unscheduleAllCallbacks();
let timeInSecond = 0.5;
this.pageViewComp.schedule(function() {
let currentIndex = this.pageViewComp.getCurrentPageIndex();
let nextIndex = currentIndex + 1;
if (nextIndex >= this.pageViewComp._pages.length) {
nextIndex = 0;
}
this.pageViewComp.scrollToPage(nextIndex, timeInSecond);
}.bind(this), 2.5);
},
setCurrentShowPage: function(index) {
this.pageViewComp._curPageIdx = index;
this.pageViewComp.scrollToOffset(this.pageViewComp._moveOffsetValue(index));
if (this.pageViewComp.indicator) {
this.pageViewComp.indicator._changedState();
}
},

阅读整个主题