cocos2d-x CCScollView的滑动颠倒问题

快速看了下CCScrollView源码,发现其实现里有个m_pContainer的CCLayer,用m_pContainer的大小来控制CCScrollView的可滑动大小,所以在不改动源码的情况下,创建CCScrollView:

 
复制代码
  1. CCSize containerSize = CCSizeMake(480, 600);
  2. CCSize scrollViewSize = CCSizeMake(480, 320);
  3. CCNode* pContainer = CCLayer::create();
  4. pContainer->setContentSize(containerSize);
  5. CCScrollView* scrollView = CCScrollView::create(scrollViewSize, pContainer);
  6. addChild(scrollView);
  7. scrollView->setDirection(CCScrollViewDirectionVertical);




此时创建的View是有了,并且也可以滑动了,但是上、下可滑动的距离却颠倒了;手指向上滑,View里的内容只能向下滑动一点,并且手松开就自动返回原位置(回滑);手指向下滑,View的内容可以滑动,并且不回滑。后测试,发现左右方向也一样是反的。 

又看了一下源码,做了些改动,原始的代码: 

 
复制代码
  1. CCPoint CCScrollView::maxContainerOffset()
  2. {
  3. return ccp(0.0f, 0.0f);
  4. }
  5. CCPoint CCScrollView::minContainerOffset()
  6. {
  7. return ccp(m_tViewSize.width - m_pContainer->getContentSize().width*m_pContainer->getScaleX(),
  8. m_tViewSize.height - m_pContainer->getContentSize().height*m_pContainer->getScaleY());
  9. }

 

改动之后:
 
复制代码
  1. CCPoint CCScrollView::maxContainerOffset()
  2. {
  3. return ccp(0, m_pContainer->getContentSize().height*m_pContainer->getScaleY() - m_tViewSize.height);
  4. }
  5. CCPoint CCScrollView::minContainerOffset()
  6. {
  7. return ccp(m_tViewSize.width - m_pContainer->getContentSize().width*m_pContainer->getScaleX(), 0);
  8. }


转自:http://www.cocoachina.com/bbs/read.php?tid=157273

posted @ 2014-11-07 11:45  猿走天下  阅读(823)  评论(0)    收藏  举报