基于cocoStudio的UIListView的可以左右滑动翻页的ListView
//WidgetSlideListView.h
class WidgetEaseInListView : public cocos2d::gui::UIListView
{
public:
static WidgetEaseInListView* create(cocos2d::gui::UIListView* pAnthor=NULL);
void doEaseIn(bool bRight2Left=true); protected:
virtual void copySpecialProperties(cocos2d::gui::Widget* model); protected:
virtual void onEaseInOver();
virtual void startEaseIn(bool bRight2Left);
virtual void tick(float delta); protected:
bool m_bRight2Left;
}; class SlideListViewDataSource
{
public:
virtual size_t getTotalItemNum() = 0;
virtual size_t getEveryPageItemNum() = 0;
virtual cocos2d::gui::UIWidget* getWidgetAt(size_t nIdx) = 0;
virtual void onPageTurnOver(size_t nCurrentPage){}
}; class WidgetSlideListView : public WidgetEaseInListView
{
enum SlideDir
{
eSlideDir_None = 0,
eSlideDir_Horizon_Left,
eSlideDir_Horizon_Right,
eSlideDir_Virtical
}; protected:
WidgetSlideListView();
virtual ~WidgetSlideListView(); public:
static WidgetSlideListView* create(SlideListViewDataSource* pDelegate,cocos2d::gui::UIListView* pAnthor=NULL); public:
void setDelegate(SlideListViewDataSource* pDelegate){ m_pDelegate = pDelegate; }
void reloadData();
size_t getCurrentPage()const{ return m_nCurrentPage; }
void turnToPage(unsigned int nPage); protected:
virtual bool init();
virtual void handleMoveLogic(const cocos2d::CCPoint &touchPoint);
virtual void handleReleaseLogic(const cocos2d::CCPoint &touchPoint);
void scheduleTurnPage(float t); protected:
SlideListViewDataSource* m_pDelegate;
size_t m_nCurrentPage;
SlideDir m_eSlideDir;
cocos2d::CCPoint m_BackPos;
};
//WidgetSlideListView.cpp
#include "../include/WidgetSlideListView.h" USING_NS_CC;
USING_NS_CC_EXT;
using namespace cocos2d::gui; WidgetEaseInListView* WidgetEaseInListView::create(UIListView* pAnthor/*=NULL*/)
{
WidgetEaseInListView* pRet = new WidgetEaseInListView();
if (pRet && pRet->init())
{
pRet->autorelease();
if (pAnthor)
{
pRet->copyProperties(pAnthor);
} return pRet;
}
else
{
delete pRet;
pRet = NULL;
return NULL;
}
} void WidgetEaseInListView::copySpecialProperties(cocos2d::gui::Widget* model)
{
UIListView::copySpecialProperties(model); setDirection(SCROLLVIEW_DIR_VERTICAL);
setBounceEnabled(true);
setTouchEnabled(true);
} void WidgetEaseInListView::tick(float delta)
{
startEaseIn(m_bRight2Left);
} void WidgetEaseInListView::doEaseIn(bool bRight2Left)
{
stopAllActions();
for (unsigned int i=0; i<getItems()->count(); i++)
{
UIWidget* pWidget = getItem(i);
pWidget->setVisible(false);
}
m_bRight2Left = bRight2Left;
scheduleOnce(schedule_selector(WidgetEaseInListView::tick),0);
} void WidgetEaseInListView::startEaseIn(bool bRight2Left)
{
setTouchEnabled(false); static const float fDelay = 0.1f;
static const float fMoveTime = 0.4f; CCArray* pActSeq = CCArray::create(); float fVisibleHeight = 0.0f;
float fTotalHeight = getSize().height;
CCArray* pArr = getItems();
int nSlidCount =0;
for (unsigned int i=0; i<pArr->count(); i++)
{
UIWidget* pWidget = getItem(i);
pWidget->setVisible(true); fVisibleHeight+=pWidget->getSize().height;
if (fVisibleHeight<fTotalHeight+pWidget->getSize().height)
{
float fOffset = (bRight2Left?1:-1)*pWidget->getContentSize().width;
CCPoint startPos = ccpAdd(pWidget->getPosition(),ccp(fOffset,0));
//CCPoint startPos = ccp(pWidget->getContentSize().width/2+fOffset,pWidget->getPosition().y);
pWidget->setPosition(startPos);
CCSequence* pAct = CCSequence::createWithTwoActions(CCDelayTime::create(fDelay*i),CCEaseBackOut::create(CCMoveBy::create(fMoveTime,ccp(-fOffset,0))));
pActSeq->addObject(CCTargetedAction::create(pWidget,pAct) ); nSlidCount++;
}
}
CCSequence* pAct = CCSequence::createWithTwoActions(CCDelayTime::create(fDelay*nSlidCount),CCCallFunc::create(this,callfunc_selector(WidgetEaseInListView::onEaseInOver)));
pActSeq->addObject(pAct); runAction(CCSpawn::create(pActSeq));
} void WidgetEaseInListView::onEaseInOver()
{
setTouchEnabled(true);
} WidgetSlideListView::WidgetSlideListView()
:m_pDelegate(NULL)
,m_nCurrentPage(0)
,m_eSlideDir(eSlideDir_None)
{ } WidgetSlideListView::~WidgetSlideListView()
{ } WidgetSlideListView* WidgetSlideListView::create(SlideListViewDataSource* pDelegate,UIListView* pAnthor/*=NULL*/)
{
WidgetSlideListView* pRet = new WidgetSlideListView();
if (pRet && pRet->init())
{
pRet->autorelease();
pRet->setDelegate(pDelegate);
if (pAnthor)
{
pRet->copyProperties(pAnthor);
} return pRet;
}
else
{
delete pRet;
pRet = NULL;
return NULL;
} } bool WidgetSlideListView::init()
{
if (UIListView::init())
{
setDirection(SCROLLVIEW_DIR_VERTICAL);
setBounceEnabled(true);
setTouchEnabled(true);
return true;
}
return false;
} void WidgetSlideListView::reloadData()
{
assert(m_pDelegate);
assert(m_pDelegate->getEveryPageItemNum()>0);
unsigned int nTotalPage = m_pDelegate->getTotalItemNum()/m_pDelegate->getEveryPageItemNum();
nTotalPage+= m_pDelegate->getTotalItemNum()%m_pDelegate->getEveryPageItemNum()>0 ? 1 : 0; assert(m_nCurrentPage>=0); removeAllItems();
if (m_pDelegate->getTotalItemNum()>0)
{
assert(m_nCurrentPage<nTotalPage); for (size_t i=0; i<m_pDelegate->getEveryPageItemNum(); i++)
{
if (m_pDelegate->getTotalItemNum()<(i+1)+m_nCurrentPage*m_pDelegate->getEveryPageItemNum())
{
break;
} UIWidget* pChild = m_pDelegate->getWidgetAt(m_nCurrentPage*m_pDelegate->getEveryPageItemNum()+i); if (!pChild)
{
break;
} pushBackCustomItem(pChild);
}
}
jumpToTop();
} void WidgetSlideListView::handleMoveLogic( const CCPoint &touchPoint )
{
_touchMovedPoint = convertToNodeSpace(touchPoint);
CCPoint delta = _touchMovedPoint - _touchBeganPoint; if (eSlideDir_None==m_eSlideDir)
{
m_eSlideDir = fabs(delta.x)>fabs(delta.y) ? eSlideDir_Horizon_Left : eSlideDir_Virtical;
m_BackPos = _innerContainer->getPosition();
} if (eSlideDir_Virtical==m_eSlideDir)
{
UIListView::handleMoveLogic(touchPoint);
}
else if (eSlideDir_None!=m_eSlideDir)
{
if (isTouchEnabled())
{
CCPoint pt = ccp(m_BackPos.x+delta.x,m_BackPos.y);
_innerContainer->setPosition(pt);
}
}
} void WidgetSlideListView::handleReleaseLogic( const CCPoint &touchPoint )
{
if (eSlideDir_Virtical==m_eSlideDir)
{
UIListView::handleReleaseLogic(touchPoint);
m_eSlideDir = eSlideDir_None;
}
else if (eSlideDir_None!=m_eSlideDir)
{
if (isTouchEnabled())
{
CCPoint delta = _touchMovedPoint - _touchBeganPoint; static const float fDelatPosX = 30;
if (delta.x<-fDelatPosX && m_pDelegate->getTotalItemNum()>(m_nCurrentPage+1)*m_pDelegate->getEveryPageItemNum())
{
m_eSlideDir = eSlideDir_Horizon_Left;
scheduleOnce( schedule_selector(WidgetSlideListView::scheduleTurnPage),0);
}
else if (delta.x>fDelatPosX && m_nCurrentPage>0)
{
m_eSlideDir = eSlideDir_Horizon_Right;
scheduleOnce( schedule_selector(WidgetSlideListView::scheduleTurnPage),0);
}
else
{
m_eSlideDir = eSlideDir_None;
_innerContainer->setPosition(m_BackPos);
}
}
} } void WidgetSlideListView::turnToPage(unsigned int nPage)
{
bool bRight2Left = m_nCurrentPage<=nPage;
m_nCurrentPage=nPage;
reloadData();
doEaseIn(bRight2Left);
m_pDelegate->onPageTurnOver(m_nCurrentPage);
} void WidgetSlideListView::scheduleTurnPage(float t)
{
if (eSlideDir_Horizon_Left==m_eSlideDir)
{
turnToPage(m_nCurrentPage+1);
}
else if (eSlideDir_Horizon_Right==m_eSlideDir)
{
turnToPage(m_nCurrentPage-1);
} m_eSlideDir = eSlideDir_None;
}
基于cocoStudio的UIListView的可以左右滑动翻页的ListView的更多相关文章
- 基于HTML5手机上下滑动翻页特效
基于HTML5手机上下滑动翻页特效.这是一款手机移动端触屏滑动翻页代码下载.效果图如下: 在线预览 源码下载 实现的代码. html代码: <section class="u-al ...
- 基于vue实现上下滑动翻页效果
18年年底的时候,一直在做年度报告的H5页面,因为项目需要,需要实现上下滑动翻页,并且上滑的页面比正常页面的比例要缩小一定比例. 效果类似于http://www.17sucai.com/pins/de ...
- 开源 侧滑 和 Tab滑动翻页 控件
侧滑 https://github.com/jfeinstein10/SlidingMenu Tab滑动翻页 https://github.com/astuetz/PagerSlidingTabStr ...
- 桌面浏览器实现滑动翻页效果(Swiper)
还是那个号称很炫的B/S展示软件,在液晶屏上展示需要有滑动翻页的效果(在同一页面滑动切换内容,不是切换页面),最后确定使用功能很强大的Swiper类库. 具体优点可参考:http://www.chin ...
- 【解决ViewPager在大屏上滑动不流畅】 设置ViewPager滑动翻页距离
在项目中做了一个ViewPager+Fragment滑动翻页的效果,在模拟器和小米手机上测试也比较正常.但是换到4.7以上屏幕测试的时候发现老是滑动失效. 因为系统默认的滑动策略是当用户滑动超过半屏之 ...
- Android中实现滑动翻页—使用ViewFlipper(dp和px之间进行转换)
Android中实现滑动翻页—使用ViewFlipper(dp和px之间进行转换) Android中dp和px之间进行转换 在xml布局文件中,我们既可以设置px,也可以设置dp(或者dip).一般情 ...
- ViewPager实现滑动翻页效果
实现ViewPager的滑动翻页效果可以使用ViewPager的setPageTransformer方法,如下: import android.content.Context; import andr ...
- cocos2d-x滑动翻页,多出一点偏移量。
cocos2d-x 2.2.3版本. 控件:ccscrollView 实现滑动翻页:创建出来的cell横向移动时会有一个惯性滑动,导致View页面不能居中.通过延迟重新设定的方式解决.
- 微信里经常看到的滑动翻页效果,slide
上个星期我们的产品姐姐让我帮她写个微信里经常看到的滑动翻页效果,今天抽空写了3个小demo(只写了webkit需要chrome模拟手机看 开启touch事件), 故此写个随笔. 1.demo1,整个大 ...
随机推荐
- 【bzoj1016】 JSOI2008—最小生成树计数
http://www.lydsy.com/JudgeOnline/problem.php?id=1016 (题目链接) 题意 求图的最小生成树计数. Solution %了下题解,发现要写矩阵树,15 ...
- BZOJ2120 数颜色
Description 墨墨购买了一套N支彩色画笔(其中有些颜色可能相同),摆成 一排,你需要回答墨墨的提问.墨墨会像你发布如下指令: 1. Q L R代表询问你从第L支画笔到第R支画笔中共有几种不同 ...
- asp.net 实现在线打印功能,jQuery打印插件PrintArea实现自动分页
使用的组件:jQuery打印插件PrintArea,有兴趣的可以研究一下. 使用方法略过,这里将介绍如何实现打印多页是可以分页. 现在提供两种方法思路: 1.根据特定的打印机型号和使用的纸张类型,然后 ...
- poj 1845 数论综合
题意:求A^B的所有因数的和 mod 9901 sol:一开始毫无思路,因为很多定理都不知道-_-|| 1. 整数的唯一分解定理: 任意正整数都有且只有一种方式写出其素因子的乘积表达式. A=(p1^ ...
- jsp学习(五)
在进行jsp与jdbc连接时,出现这样一个错误,提示如下: java.net.ConnectException: Connection refused: connect 后来发现是由于mysql数据库 ...
- LINUX下为ORACLE数据库设置大页--hugepage
在Linux中配置hugepage可以提高oracle的性能,减少oracle sga的页交换,类似于aix中的lagepage. 为什么 使用大页? LINUX内存的默认块大小是4K如果SGA为:1 ...
- POJ3267 The Cow Lexicon(DP+删词)
The Cow Lexicon Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9041 Accepted: 4293 D ...
- how to combine jpg + separate alpha in png?
http://www.tasharen.com/forum/index.php?topic=4018.msg19784#msg19784 I have tons of large sprites, I ...
- 新浪微博客户端(32)-设置相册图片的contentMode
DJStatusPhotoView.m #import "DJStatusPhotoView.h" #import "UIImageView+WebCache.h&quo ...
- 使用Fabric进行crash收集统计
主要是帮助自己记一下地址. 1 申请Crashlytics服务:http://try.crashlytics.com 2 下载Fabric客户端,帮助集成Crashlytics到自己的项目中:http ...