cocos代码研究(24)Widget子类PageView学习笔记
2015-10-09 20:49
736 查看
理论基础
PageView类又称Layout的管理器,可以让用户在多个Layout之间左右或者上下切换显示,继承自 Layout 。代码实践
static PageView * create ()创建一个空的PageView。
void addWidgetToPage (Widget *widget, ssize_t pageIdx, bool forceCreate)
把一个widget添加到指定的PageView页中。
void addPage (Layout *page)
往PageView的最后插入一页。
void insertPage (Layout *page, int idx)
在指定位置插入一页。
void removePage (Layout *page)
从PageView中移除一页。
void removePageAtIndex (ssize_t index)
移除指定位置的页。
void setDirection (Direction direction)
变更容器翻页方向。
Direction getDirection () const
获取容器翻页方向。
void removeAllPages ()
移除PageView中所有页。
void scrollToPage (ssize_t idx)
滚动到一个指定的页。
ssize_t getCurPageIndex () const
获取当前显示页的索引号。
void setCurPageIndex (ssize_t index)
直接跳转至指定页面(非滚动)
Vector< Layout * > & getPages ()
获取所有页的列表。
Layout * getPage (ssize_t index)
获取指定的页。
void addEventListenerPageView (Ref *target, SEL_PageViewEvent selector)
添加一个页面切换时的回调函数,当页面切换时被调用。
void addEventListener (const ccPageViewCallback &callback)
添加一个页面切换时的回调函数,当页面切换时被调用。
void setCustomScrollThreshold (float threshold)
如果没有指定该值,pageView会在滚到页面一半时切换到下一页。
float getCustomScrollThreshold () const
请求设定的切换页面门限值。
void setUsingCustomScrollThreshold (bool flag)
是否使用用户设置的切换页面门限值。 如果设为false,那么pageView会在滚到页面一半时切换到下一页。
bool isUsingCustomScrollThreshold () const
请求是否使用用户自定义页面切换门限值。
实例:
// Create the page view PageView* pageView = PageView::create(); pageView->setContentSize(Size(240.0f, 100.0f)); Size backgroundSize = background->getContentSize(); pageView->setPosition(Vec2((widgetSize.width - backgroundSize.width) / 2.0f + (backgroundSize.width - pageView->getContentSize().width) / 2.0f, (widgetSize.height - backgroundSize.height) / 2.0f + (backgroundSize.height - pageView->getContentSize().height) / 2.0f + 20)); int pageCount = 4; for (int i = 0; i < pageCount; ++i) { Layout* layout = Layout::create(); layout->setContentSize(Size(240.0f, 130.0f)); ImageView* imageView = ImageView::create("cocosui/scrollviewbg.png"); imageView->setScale9Enabled(true); imageView->setContentSize(Size(240, 130)); imageView->setPosition(Vec2(layout->getContentSize().width / 2.0f, layout->getContentSize().height / 2.0f)); 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 / 2.0f, layout->getContentSize().height / 2.0f)); layout->addChild(label); pageView->insertPage(layout,i); } _uiLayer->addChild(pageView); pageView->setName("pageView");
相关文章推荐
- 【转载】cocos2d-x2.2.3和android的平台环境
- cocos2d 改掉游戏的图标和开始图片
- Photoshop脚本代码一键生成所有cocos2d项目下的IOS图标
- cocos代码研究(23)Widget子类ScrollView学习笔记
- 【cocos2dx 加载资源目录】
- cocos2d CascadeOpacity 小坑
- 【cocos2dx】卡牌记忆游戏(3)——优化杂谈
- 【cocos2dx】卡牌记忆游戏(2)——游戏场景
- 【cocos2dx】卡牌记忆游戏(1)——卡牌类
- cocos2dx3.3+vs2012 创建项目
- cocos2d js键盘按键相关
- cocos2d-js 入门之碰撞
- Cocos2d-x 3.0 事件系统【转】
- cocos代码研究(22)Widget子类Layout学习笔记
- 【Cocos2dx】精灵触摸跳跃功能
- Cocos2dX 动作结束回调应用
- 用cocos2d-x 自制flappy bird
- 更新Cocos2D支持Xcode 7
- 更新Cocos2D支持Xcode 7
- 更新Cocos2D支持Xcode 7