cocos代码研究(24)Widget子类PageView学习笔记
理论基础
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 + )); int pageCount = ;
for (int i = ; 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(, ));
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+)), "fonts/Marker Felt.ttf", );
label->setColor(Color3B(, , ));
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");
cocos代码研究(24)Widget子类PageView学习笔记的更多相关文章
- cocos代码研究(25)Widget子类PageView学习笔记
基础理论 ListView控件是一个显示滚动项目列表的视图组. 列表项是通过使用addChild或insertDefaultItem插入到列表中的,继承自ScrollView. 代码实践 static ...
- cocos代码研究(1)Node学习笔记
理论部分 Node类继承自Ref类,是cocos框架中基础底层的一个封装类,与画面渲染相关的类一般都是继承自该类,例如Scene,Layer,Sprite,Sprite3D,Label,SpriteB ...
- cocos代码研究(5)Action学习笔记
理论部分 Action类也是cocos核心基础类之一,在游戏中起着非常重要的作用,继承自Ref,被 FiniteTimeAction(有限时间动作), Follow , 以及 Speed 继承. 有限 ...
- cocos代码研究(2)Label学习笔记
理论部分 Label类继承自Node类,中文翻译文字与字体,通常在应用开发中为模块作为提示和描述的作用,主要有3中不同的创建方式. 1.通过ttf字体包创建,通过指定本地已有的ttf格式的字体文件,创 ...
- cocos代码研究(1)sprite学习笔记
各种方法创建Sprite和Animate //图片创建法 参数一:图片资源路径 参数二:Rect选区 auto sprite = Sprite::create(, )); addChild(sprit ...
- cocos代码研究(2)Layer学习笔记
auto layer = Layer::create(); /*************华丽分割线*************/ auto layer = LayerColor::create(Colo ...
- cocos代码研究(22)Widget子类Layout学习笔记
理论基础 一个包含控件的容器. 子节点可以根据布局类型重新排序,它还可以开启剪裁,设置背景图像和颜色.继承自Widget,以及LayoutProtocol. 被 HBox, PageView, Rel ...
- cocos代码研究(17)Widget子类RadioButtonGroup学习笔记
理论基础 RadioButtonGroup可以把指定的单选按钮组织起来, 形成一个组, 使它们彼此交互. 在一个RadioButtonGroup, 有且只有一个或者没有RadioButton可以处于被 ...
- cocos代码研究(16)Widget子类RadioButton学习笔记
理论基础 RadioButton是一种特定类型的两状态按钮,它与复选框相似.它可以 和RadioButtonGroup一起使用,形成一个"组".继承自AbstractCheckBu ...
随机推荐
- Java精选笔记_多线程(创建、生命周期及状态转换、调度、同步、通信)
线程概述 在应用程序中,不同的程序块是可以同时运行的,这种多个程序块同时运行的现象被称作并发执行. 多线程可以使程序在同一时间内完成很多操作. 多线程就是指一个应用程序中有多条并发执行的线索,每条线索 ...
- POJ 1946 Cow Cycling(抽象背包, 多阶段DP)
Description The cow bicycling team consists of N (1 <= N <= 20) cyclists. They wish to determi ...
- Python 中文乱码
1.首行添加 # -*- coding:gb2312 -*- # -*- coding:utf-8 -*- 2.PyCharm设置 在File->setting->File Encodin ...
- url重写(urlrewrite)的一些系统变量
学php也有3年了,一直对url重写不是很了解,本学用到的话都是百度一下,再复制作简单修改,一些变量的参数都不太了解什么意思,难得今天有时间,做个笔记吧! 1)可用的一些系统变量,在重写条件和重写规则 ...
- Android中Parcelable和Serializable接口用法
1. Parcelable接口 Interface for classes whose instances can be written to and restored from a Parcel. ...
- img-图片二进制流 64位前端显示
碰到的场景:因为使用iframe子窗口打开,多张的二维码图片创建方法调用,导致页面打开缓慢, 所以将调取方式转换成<img src="data:image/png;base64,@it ...
- WEB安全番外第一篇--其他所谓的“非主流”漏洞:URL跳转漏洞与参数污染
一.URL跳转篇: 1.原理:先来看这段代码: <?php if(isset($_GET["url_redircetion_target"])){ $url_redirect ...
- C#的命令行工具
在最开始学java的时候我们一般用 记事本 + 命令行,在命令行里边进行编译和运行, C#也有类似的东西(csc工具),在学习C#语言的时候可以用 文本编辑器来编写代码,然后用C#的命令行工具来编译 ...
- WCF(四) 深入契约
服务契约中的请求-响应操作 1.请求-响应模式 [OperationContract]//1默认就是 请求-相应 Requst- Replay DateTime GetDateTime(); [Ope ...
- SqlServer复杂存储过程
SqlServer复杂存储过程 CREATE PROCEDURE FETCH_GOOUT_INFO AS BEGIN WITH l as(SELECT A.ZJHM, O.KSQR, O.JSRQ, ...