在使用PageView做关卡选择界面时,发现滑动切换界面很不好用,用以下代码解决:
新建一个类继承PageView:
class MyPageView : publicPageView { public: void handleReleaseLogic(constPoint &touchPoint) override { if (_pages.size() <=0) { return; } Widget* curPage = _pages.at(_curPageIdx); if (curPage) { Point curPagePos = curPage->getPosition(); ssize_t pageCount = _pages.size(); float curPageLocation = curPagePos.x; float pageWidth = getSize().width; float boundary = pageWidth/2.0f; if(boundary > 50.0f)boundary = 50.0f;//调整灵敏度 if (curPageLocation <= -boundary) { if (_curPageIdx >= pageCount-1) { scrollPages(-curPageLocation); } else { scrollToPage(_curPageIdx+1); } } else if (curPageLocation >= boundary) { if (_curPageIdx <=0) { scrollPages(-curPageLocation); } else { scrollToPage(_curPageIdx-1); } } else { scrollToPage(_curPageIdx); } } } CREATE_FUNC(MyPageView); };
在使用PageView的地方用MyPageView就可以了,非常好用。
原文链接:https://www.f2er.com/cocos2dx/347159.html