加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

cocos2dx 3.x pageview 滑动优化

发布时间:2020-12-14 21:20:18 所属栏目:百科 来源:网络整理
导读:cocos的pageview 滑动起来相当费力每次都要滑倒屏幕的一般才能滑过去 我们直接修改cocos的源码就可以达到优化的效果 修改cocos/ui/UIPageView.cpp中的void PageView::handleReleaseLogic(Touch *touch)函数 void PageView::handleReleaseLogic(Touch *touch)

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; 就好滑多了

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读