UIPageView

mac2022-06-30  91

local ui=require("framework.ui")local MainScene = class("MainScene", function() return display.newScene("MainScene")end)

function MainScene:ctor() -- cc.ui.UILabel.new({ -- UILabelType = 2, text = "Hello, World", size = 64}) -- :align(display.CENTER, display.cx, display.cy) -- :addTo(self) --不同label的创建方法; -- local label=display.newTTFLabel({ -- text="龙日天", -- size=70 -- })local label=ui.newTTFLabel({ text="龙日天", size=80, color=cc.c3b(255, 0, 0) }) label:setPosition(display.cx, display.cy) label:addTo(self) --UIPageView的使用 self.pv = cc.ui.UIPageView.new({ viewRect = cc.rect(0,0,960,640) , --设置位置和大小 column = 3 , row = 3, --列和行的数量 padding = {left = 20 , right = 20 , top = 20 , bottom = 20} , --整体的四周距离 columnSpace = 10 , rowSpace = 10 --行和列的间距 })--[[ 实际上,除了 C++ 回调 Lua 函数之外,在其他所有需要回调的地方都可以使用 handler()。@param mixed obj Lua 对象@param function method 对象方法@return function

function handler(obj, method) return function(...) return method(obj, ...) endend]] :onTouch(handler(self,self.touchListener))--handler调用回调函数; :addTo(self) for i = 1 , 27 do -- 创建一个新的页面控件项-- @function [parent=#UIPageView] newItem-- @return UIPageViewItem#UIPageViewItem local item = self.pv:newItem() local content content = display.newColorLayer( cc.c4b(math.random(250), math.random(250), math.random(250), math.random(250))) content:setContentSize(240,140) content:setTouchEnabled(false) item:addChild(content) -- 为每个单独的item添加一个颜色图块 self.pv:addItem(item) --为pageview添加item end self.pv:reload() --需要重新刷新才能显示 -- self:copyJson()endfunction MainScene:touchListener(event) dump(event, "TestUIPageViewScene - event") local listView =event.listView if 3 == event.itemPos then listView:removeItem(event.item,true) print("longyongzhi") endendfunction MainScene:onEnter()end

function MainScene:onExit()end

return MainScene

转载于:https://www.cnblogs.com/xiajianwei/p/5122331.html

相关资源:JAVA上百实例源码以及开源项目
最新回复(0)