下面是基于 ccui.PageView 创建分页视图的示例代码:循环构造 8 个 Layout,每个 Layout 作为一页添加到 PageView,并在最后注册翻页事件。

    ---pageView
                
                    local page=ccui.PageView:create()
                
                    for i=1,8 do
                
                ---创建layout,内容添加到layout
                        local layout=ccui.Layout:create()
                        layout:setContentSize(700,700)
                
                        layout:setPosition(0,0)
                        local s=i .. ".png"
                        local xx= ccui.Button:create(s,s,s,0)
                        layout:addChild(xx)
                        xx:setPosition(350,700/2)
                        page:addPage(layout)---一个layout 为一个 page内容
                
                        xx:setScale(1.5)
                    end
                
                
                
                
                    layer:addChild(page)
                
                    page:setContentSize(700,700)
                    page:setTouchEnabled(true)
                    page:setAnchorPoint(cc.p(0.5,0.5))
                    page:setPosition(WIDTH_MAX/2,HEIGHT_MAX/2)
                
                
                    --注册事件
                
                      page:addEventListener(function(sender,event)
                        if event==ccui.PageViewEventType.turning then
                            self:setName(page:getCurPageIndex())
                
                        end
                
                    end)