本文来自http://blog.youkuaiyun.com/runaying ,引用必须注明出处!
cocos2d-X 节点(UIPageView.h)API
温馨提醒:为了大家能更好学习,强烈推荐大家看看本人的这篇博客 Cocos2d-X权威指南笔记
一个翻页视图,里面包含了一些对页面操作的方法
/////cocos2d-x-3.0alpha0/extensions/CocoStudio/GUI/UIWidgets/ScrollWidget
// 一个翻页视图,里面包含了一些对页面操作的方法
#ifndef __UIPAGEVIEW_H__
#define __UIPAGEVIEW_H__
#include "../../Layouts/Layout.h"
#include "UIScrollInterface.h"
NS_CC_EXT_BEGIN
typedef enum
{
PAGEVIEW_EVENT_TURNING,
}PageViewEventType;
typedef void (Object::*SEL_PageViewEvent)(Object*, PageViewEventType);
#define pagevieweventselector(_SELECTOR)(SEL_PageViewEvent)(&_SELECTOR)
typedef enum {
PAGEVIEW_TOUCHLEFT,
PAGEVIEW_TOUCHRIGHT
}PVTouchDir;
class UIPageView : public Layout , public UIScrollInterface
{
public:
/**
* Default constructor
*/
UIPageView();
/**
* Default destructor
*/
virtual ~UIPageView();
/**
* Allocates and initializes.
*/
static UIPageView* create();
/**
* Add a widget to a page of pageview. //把 widget 添加到页面视图里面的一个页面
*
* @param widget widget to be added to pageview.
*
* @param pageIdx index of page.
*
* @param forceCreate if force create and there is no page exsit, pageview would create a default page for adding widget.
*/
void addWidgetToPage(UIWidget* widget, int pageIdx, bool forceCreate);
/**
* Push back a page to pageview. //从页面视图里面回退一个页面
*
* @param page page to be added to pageview.
*/
void addPage(Layout* page);
/**
* Inert a page to pageview. //在页面视图里面插入一个页面
*
* @param page page to be added to pageview.
*/
void insertPage(Layout* page, int idx);
/**
* Remove a page of pageview. //从页面视图里面移除一个页面
*
* @param page page which will be removed.
*/
void removePage(Layout* page);
/**
* Remove a page at index of pageview. //从页面视图里面移除索引对应的页面
*
* @param index index of page.
*/
void removePageAtIndex(int index);
/**
* scroll pageview to index. //滚动页面视图索引。
*
* @param idx index of page.
*/
void scrollToPage(int idx);
/**
* Gets current page index. //获取当前页的索引
*
* @return current page index.
*/
int getCurPageIndex() const;
// event //添加事件监听
void addEventListener(Object *target, SEL_PageViewEvent selector);
//override "removeChild" method of widget. 覆盖 widget 的 removeChild 方法
virtual bool removeChild(UIWidget* widget);
//override "removeAllChildrenAndCleanUp" method of widget.
virtual void removeAllChildren();
//override "onTouchBegan" method of widget.
virtual bool onTouchBegan(const Point &touchPoint);
//override "onTouchMoved" method of widget.
virtual void onTouchMoved(const Point &touchPoint);
//override "onTouchEnded" method of widget.
virtual void onTouchEnded(const Point &touchPoint);
//override "onTouchCancelled" method of widget.
virtual void onTouchCancelled(const Point &touchPoint);
//override "update" method of widget. //覆盖 widget 的update 方法
virtual void update(float dt);
/**
* Returns the "class name" of widget. //返回 widget 的名字
*/
virtual const char* getDescription() const;
protected:
virtual bool addChild(UIWidget* widget);
virtual bool init();
Layout* createPage();
float getPositionXByIndex(int idx);
void updateBoundaryPages();
virtual void handlePressLogic(const Point &touchPoint);
virtual void handleMoveLogic(const Point &touchPoint);
virtual void handleReleaseLogic(const Point &touchPoint);
virtual void interceptTouchEvent(int handleState, UIWidget* sender, const Point &touchPoint);
virtual void checkChildInfo(int handleState, UIWidget* sender, const Point &touchPoint);
virtual bool scrollPages(float touchOffset);
void movePages(float offset);
void pageTurningEvent();
void updateChildrenSize();
void updateChildrenPosition();
virtual void onSizeChanged();
virtual void setClippingEnabled(bool able){Layout::setClippingEnabled(able);};
protected:
int _curPageIdx;
Array* _pages;
PVTouchDir _touchMoveDir;
float _touchStartLocation;
float _touchEndLocation;
float _touchMoveStartLocation;
Point _movePagePoint;
UIWidget* _leftChild;
UIWidget* _rightChild;
float _leftBoundary;
float _rightBoundary;
bool _isAutoScrolling;
float _autoScrollDistance;
float _autoScrollSpeed;
int _autoScrollDir;
float _childFocusCancelOffset;
Object* _eventListener;
SEL_PageViewEvent _eventSelector;
};
NS_CC_EXT_END
#endif /* defined(__UIPageView__) */

本文主要介绍了cocos2d-X框架中UIPageView节点的API,包括其翻页视图功能和相关页面操作方法。
900

被折叠的 条评论
为什么被折叠?



