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();//删除所有页