PageView的設置

1、創建一個PageView控件,自動生成background精靈和mask的view視圖和indicator

View下面有一個content(Layout類型) ,content可以存放每頁內容

頁面指示器,可以清晰看當前是多少也

2、監聽PageView事件

    // 監聽事件

    onPageEvent (sender, eventType) {

        // 翻頁事件

        if (eventType !== cc.PageView.EventType.PAGE_TURNING) {

            return;

        }

        console.log("當前所在的頁面索引:" + sender.getCurrentPageIndex());

}

PageView控件的屬性

    properties: {

        target: cc.PageView,

    },

this.target.setCurrentPageIndex(0)//設置當前在哪頁

this.target.getCurrentPageIndex()//當前頁的索引

this.target.scrollToPage(0);//滾動到哪頁  第二個參數爲滾動所需時間,默認值爲 0.3 秒

this.target.addPage(this._createPage());//在最後頁添加一頁

this.target.insertPage(this._createPage(), this.target.getCurrentPageIndex());//在某頁添加一頁

this.target.getPages();//總共有多少頁

this.target.removePage(pages[pages.length - 1]);//刪除最後一頁

this.target.removePageAtIndex(this.target.getCurrentPageIndex());//刪除當前頁

this.target.removeAllPages();//刪除所有頁

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章