cocos2d-lua3.7控件篇(四)-ScrollView demo
【摘要】
效果如下:
local MenuScene = class("MenuScene", function() return display.newScene("MenuScene")end) function MenuScene:ctor() print("ctor")local tests = { ...
效果如下:
-
local MenuScene = class("MenuScene", function()
-
return display.newScene("MenuScene")
-
end)
-
-
function MenuScene:ctor()
-
print("ctor")
-
local tests = {
-
"Test_NodeFrameEvent",
-
"Test_NodeEvent",
-
"Test_KeypadEvent",
-
"Test_NodeTouchEvent",
-
"Test_AccelerometerEvent",
-
"Test_CocosStudio",
-
"Test_Audio",
-
}
-
-
local scrollView = ccui.ScrollView:create()
-
scrollView:addTo(self)
-
scrollView:align(display.TOP_CENTER, display.cx, display.top)
-
self.scrollView = scrollView
-
-
local total = 0
-
local btnSize = nil
-
for i = #tests, 1, -1 do
-
local btn = ccui.Button:create()
-
btn:setTitleText(tests[i])
-
btn:setTitleFontSize(24)
-
btn:addTouchEventListener(function(sender, eventType)
-
if 2 == eventType then
-
print(i)
-
-
end
-
end)
-
if not btnSize then
-
btnSize = btn:getContentSize()
-
end
-
btn:pos((display.width - btnSize.width) / 2 + btnSize.width / 2,
-
btnSize.height * total + btnSize.height / 2)
-
total = total + 1
-
-
scrollView:addChild(btn)
-
end
-
-
local totalHeight = btnSize.height * total
-
scrollView:setInnerContainerSize(cc.size(display.width, totalHeight))
-
local scrollHeight = display.height
-
if totalHeight < scrollHeight then
-
scrollHeight = totalHeight
-
end
-
scrollView:setContentSize(cc.size(display.width, scrollHeight))
-
-
end
-
-
function MenuScene:onEnter()
-
end
-
-
function MenuScene:onExit()
-
end
-
-
return MenuScene
文章来源: yujiang.blog.csdn.net,作者:鱼酱2333,版权归原作者所有,如需转载,请联系作者。
原文链接:yujiang.blog.csdn.net/article/details/78715989
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)