首页 > 代码库 > cocos2d-x3.0 PageView
cocos2d-x3.0 PageView
.h加入例如以下代码:
void pageViewEvent(Ref *pSender, PageViewEventType type);
.m
layout = Layout::create(); layout->setSize(Size(widgetSize.width, widgetSize.height)); //横向排列,这里相似Android里的线性布局 //layout->setLayoutType(LAYOUT_RELATIVE); /*以图片为背景*/ layout->setBackGroundImageScale9Enabled(true); layout->setBackGroundImage("green_edit.png"); layout->setPosition(Point(0,0)); addChild(layout); /******************************************************************************************/ PageView* pageView = PageView::create(); pageView->setSize(Size(480, 260)); pageView->setPosition(Point(widgetSize.width / 2, widgetSize.height / 2)); for (int i = 0; i < 3; i++) { Layout* layout1 = Layout::create(); layout1->setSize(Size(480, 260)); ImageView* imageView = ImageView::create("scrollviewbg.png"); imageView->setScale9Enabled(true); imageView->setSize(Size(480, 260)); imageView->setPosition(Point(layout1->getSize().width / 2, layout1->getSize().height / 2)); layout1->addChild(imageView); Text* label = Text::create(StringUtils::format("page %d",(i+1)), "fonts/Marker Felt.ttf", 30); label->setColor(Color3B(92, 192, 192)); label->setPosition(Point(layout1->getSize().width / 2.0f, layout1->getSize().height / 2.0f)); layout1->addChild(label); pageView->addPage(layout1); } pageView->addEventListenerPageView(this, pagevieweventselector(LayoutTest::pageViewEvent)); layout->addChild(pageView);
void LayoutTest::pageViewEvent(cocos2d::Ref *pSender, PageViewEventType type) { switch (type) { case cocos2d::ui::PAGEVIEW_EVENT_TURNING: { PageView* pageView = dynamic_cast<PageView*>(pSender); log("%d",pageView->getCurPageIndex() + 1); } break; default: break; } }
cocos2d-x3.0 PageView
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。