void pageViewEvent(Ref* pSender, cocos2d::ui::PageView::EventType type);
-------------------------------------------------------------------------------------------------------------------------------------
Size size = Director::getInstance()->getVisibleSize();
//Layout* root = Layout::create();
//root->setContentSize(Size(500, 400));
//root->setAnchorPoint(Point(0.5f, 0.5f));
//root->setBackGroundColorType(Layout::BackGroundColorType::SOLID);
//root->setBackGroundColor(Color3B::GREEN);
//root->setPosition(Vec2(size.width / 2, size.height / 2));
//this->addChild(root);
PageView* pView = PageView::create();
pView->setContentSize(Size(400,300));
pView->setBackGroundColor(Color3B::BLUE);
//pView->setAnchorPoint(Point(0.5f,0.5f));
Size backgroundSize = pView->getContentSize();
pView->setPosition(Vec2(backgroundSize.width / 2,backgroundSize.height /2));
pView->addEventListener(CC_CALLBACK_2(HelloWorld::pageViewEvent, this));
this->addChild(pView);
pView->removeAllPages();
int pageCount = 4;
for (int i = 0; i < pageCount; ++i)
{
Layout* layout = Layout::create();
layout->setAnchorPoint(Point(0.5f,0.5f));//设置锚点
layout->setContentSize(Size(400, 300));
ImageView* imageView = ImageView::create("scrollviewbg.png");
//imageView->setAnchorPoint(Point(0.5f,0.5f));
imageView->setScale9Enabled(true);
//imageView->setScale(0.5f);
imageView->setContentSize(Size(400, 300));
imageView->setPosition(Vec2(layout->getContentSize().width , layout->getContentSize().height ));
layout->addChild(imageView);
Text* label = Text::create(StringUtils::format("page %d", (i + 1)), "fonts/Marker Felt.ttf", 30);
label->setColor(Color3B(192, 192, 192));
label->setPosition(Vec2(layout->getContentSize().width, layout->getContentSize().height));
layout->addChild(label);
pView->insertPage(layout, i);
}
//pView->removePageAtIndex(0);//去掉第一个
pView->scrollToPage(pageCount - 2);//默认显示指定项
void HelloWorld::pageViewEvent(Ref* pSender, cocos2d::ui::PageView::EventType type)
{
switch (type)
{
case PageView::EventType::TURNING:
{
PageView* pageView = dynamic_cast<PageView*>(pSender);
CCLOG("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
CCLOG("liubin--->%s",CCString::createWithFormat("page = %ld", pageView->getCurPageIndex() + 1)->getCString());
//_displayValueLabel->setString(CCString::createWithFormat("page = %ld", pageView->getCurPageIndex() + 1)->getCString());
}
break;
default:
break;
}
}