zoukankan      html  css  js  c++  java
  • 采用cocos2d-x lua 的listview 实现pageview的翻页效果之上下翻页效果

    --翻页滚动效果
    local function fnScrollViewScrolling( sender,eventType)
        -- body
        if eventType == 10 then
            local bposX = sender:getPercentage()*100
            _bPosX = bposX
        end
        if not _bPosX then
            return
        end
        print("-------bposX=",_bPosX)
        if ccui.ScrollviewEventType.scrolling == eventType or eventType == 9 then
            _IsRolling = true    
        elseif eventType == 12 then
            local edposX = sender:getPercentage()*100
            local dispox = edposX - _bPosX
            print("--------dispox=",dispox)
            if dispox < 0 then
                _currPercent = _currPercent - _addPercent
                if _currPercent >= 100 then
                    _currPercent = 100
                end
            elseif dispox > 0 then
                _currPercent = _currPercent + _addPercent
                if _currPercent <= 0 then
                    _currPercent = 0
                end
            end    
            sender:scrollToPercentVertical(_currPercent,0.1,false)            
            print("--------_currPercent=,_addPercent=",_currPercent,_addPercent)
            _IsRolling = false
        end
    end
    --绘制商店列表数据
    function shopItemList( pBg,tItem )
        -- body
        require "src/libs/LuaListView"
        local itemList = pBg:getChildByTag(999)
        if not itemList then
            itemList = LuaListView:create()
            itemList:setBounceEnabled(true)
            itemList:setSize(cc.size(775, 318))
            itemList:setPosition(387.5,159+10)--230
            itemList:setAnchorPoint(cc.p(0.5,0.5))
            itemList:setDirection(ccui.ScrollViewDir.vertical)
            itemList:addEventListenerListView(fnScrollViewScrolling)
            itemList:setTag(999)
            pBg:addChild(itemList)
        else
            itemList:removeAllItems()
            _t_item = {}
        end
        local point_y = 52
        local num = math.ceil(#tItem/2)
        local addLayNum = math.mod(num,3)--当不够整页的话根据差别的个数添加空白条目实现上下整体翻页效果
        print("-----------------num=,addLayNum=",num,addLayNum)
        local layoutSize = cc.size(775,106)
        for i=1,num do
            local dLayout = ccui.Layout:create()
            dLayout:setSize(layoutSize)

            if tItem[2*i-1] then
                local itemInfo1 = drawShopItemInfo(tItem[2*i -1],2*i -1)
                itemInfo1:setPosition(194,point_y) --67
                dLayout:addChild(itemInfo1)
            end
            if tItem[2*i] then
                local itemInfo2 = drawShopItemInfo(tItem[2*i],2*i)
                itemInfo2:setPosition(582,point_y)
                dLayout:addChild(itemInfo2)
            end
            itemList:pushBackCustomItem(dLayout)
        end
        if addLayNum ~= 0 then
            local disNum = 3- addLayNum
            for i=1,disNum do
                local dLayout = ccui.Layout:create()
                dLayout:setSize(layoutSize)
                itemList:pushBackCustomItem(dLayout)
            end
        end
        local height = itemList:getInnerContainer():getContentSize().height-318
        print("itemList:getInnerContainer():getContentSize().height=",itemList:getInnerContainer():getContentSize().height)
        _addPercent=(318/height)*(-100)
    end

  • 相关阅读:
    C语言运算符优先级和口诀
    跨域问题的解决方案 php
    浅谈跨域攻击及预防
    浅析Websocket--PHP
    linux下的删除目录和文件的方法
    python魔法方法
    双指针
    python常用模块
    python三大器
    对闭包的误区
  • 原文地址:https://www.cnblogs.com/annapolis/p/5251173.html
Copyright © 2011-2022 走看看