cocos2dx 3.x pageview 滑动优化

cocos的pageview 滑动起来相当费力每次都要滑倒屏幕的一般才能滑过去

我们直接修改cocos的源码就可以达到优化的效果

修改cocos/ui/UIPageView.cpp中的void PageView::handleReleaseLogic(Touch *touch)函数

void PageView::handleReleaseLogic(Touch *touch)
{
    if (this->getPageCount() <= 0)
    {
        return;
    }
    Widget* curPage = dynamic_cast<Widget*>(this->getPages().at(_curPageIdx));
    if (curPage)
    {
        Vec2 curPagePos = curPage->getPosition();
        ssize_t pageCount = this->getPageCount();
        float curPageLocation = curPagePos.x;
        float pageWidth = getContentSize().width;
        if (!_usingCustomScrollThreshold) {
            <span style="color:#ff0000;">_customScrollThreshold = pageWidth / 2.0;</span>
        }
        float boundary = _customScrollThreshold;
        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);
        }
    }
}

 <span style="color:#ff0000;">_customScrollThreshold = pageWidth / 2.0;</span>
修改这行代码就可以改变滑动的距离 把它改为_customScrollThreshold = pageWidth / 6.0; 就好滑多了

相关文章

    本文实践自 RayWenderlich、Ali Hafizji 的文章《...
Cocos-code-ide使用入门学习地点:杭州滨江邮箱:appdevzw@1...
第一次開始用手游引擎挺激动!!!进入正题。下载资源1:从C...
    Cocos2d-x是一款强大的基于OpenGLES的跨平台游戏开发...
1.  来源 QuickV3sample项目中的2048样例游戏,以及最近《...
   Cocos2d-x3.x已经支持使用CMake来进行构建了,这里尝试...