关于pageView组件的问题

现在pageView组件到了最后最后一个index 改变index为0 图就会横拉到最开始的地方,如何才能把第一张拼接到最后一张,平滑过渡的滚动轮播,而不是有一个倒置向前的样式的滚动轮播

怎么才能在i到了最后的时候,把最开始的那一张从右边加入,而不是倒退到第一张那种效果

:joy:你一开始就加多两张不就可以了吗?最前面加最后一张,最后面加第一张

他会有拉动的效果,你不行试试

你说的就是这样的方式吧

当他拉到最后一张时,再往右拉那就是处理添加的第一张,当拉动结束后直接设置坐标到第一张位置(因为第一张是处理添加的最后一张),往前拉同理

写得简单了些。你试试,我加入了对象池来提升性能。

        var _pool = new cc.NodePool();
        this.pageView.node.on('scroll-began', () => {
            if (this.pageView.getCurrentPageIndex() == this.pageView.content.childrenCount - 1) {
                if (!this.newPage) {
                    this.newPage = cc.instantiate(this.pageView.getPages()[0]);
                }
                this.pageView.addPage(this.newPage);

            }
        });

        this.pageView.node.on('scroll-ended', () => {
            if (this.pageView.getPages().length == 4) {
                _pool.put(this.pageView.content.children[1]);
                this.newPage = _pool.get();
                this.pageView._pages.splice(1, 1);
                this.pageView._updatePageView();
            }
        })

这个功能有没想优化下,然后更新到api里面?

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();
}
},

往后轮播挺顺畅的,往前轮播到第一页时就会闪一下