- 本帖最后由 simon9821 于 2012-7-17 14:26 编辑 *
问题解决了。。。另外请问下怎样才有uiscrollview paging 效果?
就是往左拖动一定距离的话,自动滚动到下一页?
问题解决了。。。另外请问下怎样才有uiscrollview paging 效果?
就是往左拖动一定距离的话,自动滚动到下一页?
怎么解决的 代码分享下哈
问题解决了。。。另外请问下怎样才有uiscrollview paging 效果?
就是往左拖动一定距离的话,自动滚动到下一页?
如何解决的啊,我遇到这个问题了,求助啊
继续关注
— Begin quote from ____
lcf8858 发表于 2012-7-21 12:47 url
继续关注
— End quote
不好意思,刚看到。
我是想的很简单,是这样解决的。
要paging效果时,m_bTouchMoved 给false值。(用的是 2.0.1)
然后判断触摸开始到结束之间移动的距离,再判断contentoffset的值。
再用setContentOffsetInDuration函数,让卡片(例)移动到中间位置。
下面是代码,感觉写有点乱,不过希望能帮到你。(c_moveDistance是scrollview滑动到下一页时的距离,生成scrollview时可以自定义赋值。)
void CCScrollView::ccTouchEnded(CCTouch* touch, CCEvent* event){ …//其他代码
//paging 效果 if (isPagingEnableX) { if (m_pTouches->count() == 0) { m_bDragging = true; m_bTouchMoved = false; }
float moveDistanceX = this->startPoint.x - touch->locationInView().x;// float moveDistanceY = this->startPoint.y - touch->locationInView().y;
if (moveDistanceX > 0) { if (moveDistanceX > 50) { CCLog("%i", this->getContainer()->getChildrenCount()); if (this->currentContentOffSet.x <= (0-(this->getContainer()->getChildrenCount()-1)*this->c_moveDistance)) { this->setContentOffsetInDuration(CCPoint(this->currentContentOffSet.x, 0), 0.2); }else { this->setContentOffsetInDuration(CCPoint(this->currentContentOffSet.x-this->c_moveDistance, 0), 0.2); this->currentContentOffSet = CCPoint(this->currentContentOffSet.x-this->c_moveDistance, 0); } }else { this->setContentOffsetInDuration(CCPoint(this->currentContentOffSet.x, 0), 0.2); } }else { if (-moveDistanceX > 50 && this->getContentOffset().x!=0) { if (this->currentContentOffSet.x >= 0.0) { this->setContentOffsetInDuration(CCPoint(0, 0), 0.2); }else { this->setContentOffsetInDuration(CCPoint(this->currentContentOffSet.x+this->c_moveDistance, 0), 0.2); this->currentContentOffSet = CCPoint(this->currentContentOffSet.x+this->c_moveDistance, 0); } }else { this->setContentOffsetInDuration(CCPoint(this->currentContentOffSet.x, 0), 0.2); } }
}}
— Begin quote from ____
iniwap 发表于 2012-7-17 16:54 url
怎么解决的 代码分享下哈
— End quote
你是说第一个问题吧?
原先设contentsize值时,是这样设的
scrollView->setContentSize(CCSize( sWidth, sHeight)),
但发现其实它是设viewsize,而不是contentsize,所以画面总是自动滚动到右边。
应该是设container的size,自己找的方法是
scrollView1->getContainer()->setContentSize(CCSize(sWidth, sHeight));
这样就能正常用了。
— Begin quote from ____
simon9821 发表于 2012-7-31 10:51 url
你是说第一个问题吧?
原先设contentsize值时,是这样设的
scrollView->setContentSize(CCSize( sWidth, …
— End quote
恩 多谢~ 不过我现在自己来实现简单的滚动以及页面切换了~
求代码分享,413742@qq.com
怎么解决的 代码分享下哈
问题解决了。。。另外请问下怎样才有uiscrollview paging 效果?
就是往左拖动一定距离的话,自动滚动到下一页?
如何解决的啊,我遇到这个问题了,求助啊
继续关注
— Begin quote from ____
simon9821 发表于 2012-7-31 10:51 url
你是说第一个问题吧?
原先设contentsize值时,是这样设的
scrollView->setContentSize(CCSize( sWidth, …
— End quote
恩 多谢~ 不过我现在自己来实现简单的滚动以及页面切换了~