Quick中UIPageView的使用

来源:互联网 发布:诸葛亮知风 编辑:程序博客网 时间:2024/05/19 23:58
为了便于看官实际操作和理解,直接上整个类
local TestUIPageViewScene = class("TestUIPageViewScene", function ( )return display.newScene("TestUIPageViewScene")end)function TestUIPageViewScene:ctor(  )app:createGrid(self)self:createPageView()endfunction TestUIPageViewScene:createPageView( )self.pv = cc.ui.UIPageView.new {        -- bgColor = cc.c4b(200, 200, 200, 120),        -- bg = "sunset.png",        viewRect = cc.rect(80, 80, 780, 480),  --左上角点和宽高,设置位置和大小        column = 3, row = 3,        ---设置有几行,有几列        padding = {left = 20, right = 20, top = 20, bottom = 20},  --边距        columnSpace = 10, rowSpace = 10}  --每个item的行间距和列间距        :onTouch(handler(self, self.touchListener))--设置监听        :addTo(self)-- 从这里可以知道,它的整个大小是780,480,每页可容纳9个Items-- padding以后的实际宽度是740,440(右左各20,上下亦如此)-- 行间距是10*2 列间距10*2那么实际上就剩下了720,420.-- 9个Items在这个上面分每个的大小应该是240,140.(Items的大小是在padding以后的区域中)    -- add items    for i=1,18 do        local item = self.pv:newItem()        local content        -- content = cc.ui.UILabel.new(        --             {text = "item"..i,        --             size = 20,        --             align = cc.ui.TEXT_ALIGN_CENTER,        --             color = display.COLOR_BLACK})        content = cc.LayerColor:create(            cc.c4b(math.random(250),                math.random(250),                math.random(250),                250))        content:setContentSize(240, 140)  --上面计算结果        content:setTouchEnabled(false)        item:addChild(content)        self.pv:addItem(item)            end    self.pv:reload()endfunction TestUIPageViewScene:touchListener(event)    dump(event, "TestUIPageViewScene - event:")    local listView = event.listView    if 3 == event.itemPos then        listView:removeItem(event.item, true)    else        -- event.item:setItemSize(120, 80)    endendreturn TestUIPageViewScene

0 0
原创粉丝点击