Cocos2d-x3.3Final(8)PageView常用成员函数(C++)

时间:2022-02-07 23:36:39

PageView * pageView = PageView::create(); //新建

pageView->setContentSize(Size(240.0f, 130.0f)); //设置大小

pageView->removeAllPages(); //清除所有页

pageView->insertPage(layout, i); //插入页

pageView->scrollToPage(pageCount-2); //滑动到该页面

pageView->addEventLIstener(CC_CALLBACK_2(HelloWorld::pageViewEvent, this));


void HelloWorld::pageViewEvent(Ref * pSender, PageView::EventType type)

{

switch (type)

{

case PageView::EventType::TRUNING:

{

PageView * pageView = dynamic_cast<PageView *>(pSender);

pageView->getCurPageIndex() + 1;

}

}

}


pageView->setCustomScrollThreshold(10.0f); //10个像素值 就翻页

btn/imageView->setPropagateTouchEvents(true); //设为true,不繁衍,不传递该事件到父容器中,该btn或imageView是pageView的子节点或孙节点

pageView->setPropagateTouchEvents(true); //不仅要设置子节点和孙节点,还要设置自己的不繁衍

btn/imageView->setSwallowTouches(true); //吞咽触摸事件,如果设为true,则touch事件不再有用,只能使用click事件。


动态添加一页:

 pageView->addPage(outerBox);

动态删除一页:

if (pageView->getPages().size() > 0)
            {
                pageView->removePageAtIndex(pageView->getPages().size()-1);
            }

删除所有页:

 pageView->removeAllPages();