Cocos2d v 4.0:找不到 PageView 委托 addEventListenerPageView
Cocos2d v 4.0 : PageView delegate addEventListenerPageView not found
在 Cocos2d v3.17 中,我们使用以下代码创建 PageView
Size size(SW, SH);
PageView* pageView = PageView::create();
pageView->setDirection(PageView::Direction::HORIZONTAL);
pageView->setContentSize(size);
pageView->setPosition(Vec2(0.0f, 0.0f));
pageView->removeAllItems();
pageView->setIndicatorEnabled(true);
pageView->setGlobalZOrder(200);
pageView->setIndicatorIndexNodesOpacity(255);
pageView->setIndicatorPosition(Vec2(SW*0.5, SH*0.2));
this->addChild(pageView, 1);
int pageCount = 4;
for (int i = 0; i < pageCount; ++i)
{
GBMapSelectionPage *page = GBMapSelectionPage::initWithParent(this, i);
page->setContentSize(size);
pageView->insertCustomItem(page, i);
}
pageView->addEventListenerPageView(this, pagevieweventselector(GBMapScreen::pageViewEvent));
事件侦听器
void GBMapScreen::pageViewEvent(Ref *pSender, PageViewEventType type)
{
switch (type)
{
case PAGEVIEW_EVENT_TURNING:
{
PageView* pageView = dynamic_cast<PageView*>(pSender);
_displayValueLabel->setString(StringUtils::format("page = %ld", static_cast<long>(pageView->getCurrentPageIndex() + 1)));
}
break;
default:
break;
}
}
在 Cocos2dx v4.0 中,缺少 addEventListenerPageView。如何获取页面滚动委托?
在Cocos2d-xv4.0中,我们可以使用addEventListener获取PageView委托
pageView->addEventListener((ui::PageView::ccPageViewCallback)CC_CALLBACK_2(GBMapScreen::pageViewEvent,this));
委托函数:
void GBMapScreen::pageViewEvent(Ref *pSender, ui::PageView::EventType EventType)
{
switch (EventType)
{
case ui::PageView::EventType::TURNING:
{
PageView* pageView = dynamic_cast<PageView*>(pSender);
int index = static_cast<int>(pageView->getCurrentPageIndex()+1);
printf("Scrolled to Page : %d\n", index);
}
break;
default:
break;
}
}
在 Cocos2d v3.17 中,我们使用以下代码创建 PageView
Size size(SW, SH);
PageView* pageView = PageView::create();
pageView->setDirection(PageView::Direction::HORIZONTAL);
pageView->setContentSize(size);
pageView->setPosition(Vec2(0.0f, 0.0f));
pageView->removeAllItems();
pageView->setIndicatorEnabled(true);
pageView->setGlobalZOrder(200);
pageView->setIndicatorIndexNodesOpacity(255);
pageView->setIndicatorPosition(Vec2(SW*0.5, SH*0.2));
this->addChild(pageView, 1);
int pageCount = 4;
for (int i = 0; i < pageCount; ++i)
{
GBMapSelectionPage *page = GBMapSelectionPage::initWithParent(this, i);
page->setContentSize(size);
pageView->insertCustomItem(page, i);
}
pageView->addEventListenerPageView(this, pagevieweventselector(GBMapScreen::pageViewEvent));
事件侦听器
void GBMapScreen::pageViewEvent(Ref *pSender, PageViewEventType type)
{
switch (type)
{
case PAGEVIEW_EVENT_TURNING:
{
PageView* pageView = dynamic_cast<PageView*>(pSender);
_displayValueLabel->setString(StringUtils::format("page = %ld", static_cast<long>(pageView->getCurrentPageIndex() + 1)));
}
break;
default:
break;
}
}
在 Cocos2dx v4.0 中,缺少 addEventListenerPageView。如何获取页面滚动委托?
在Cocos2d-xv4.0中,我们可以使用addEventListener获取PageView委托
pageView->addEventListener((ui::PageView::ccPageViewCallback)CC_CALLBACK_2(GBMapScreen::pageViewEvent,this));
委托函数:
void GBMapScreen::pageViewEvent(Ref *pSender, ui::PageView::EventType EventType)
{
switch (EventType)
{
case ui::PageView::EventType::TURNING:
{
PageView* pageView = dynamic_cast<PageView*>(pSender);
int index = static_cast<int>(pageView->getCurrentPageIndex()+1);
printf("Scrolled to Page : %d\n", index);
}
break;
default:
break;
}
}