码迷,mamicode.com
首页 > 其他好文 > 详细

行排序的逻辑

时间:2014-05-07 19:04:15      阅读:322      评论:0      收藏:0      [点我收藏+]

标签:class   tar   get   strong   art   c   

1.lua脚本部分

--------------------------此部分封装了排序的方法-------------------------------------

         function unlock(sender)
             local senderName=sender:getPropertyByName("name");
             move[senderName]=0;
         end;

         function lock(sender)
            local senderName=sender:getPropertyByName("name");
             move[senderName]=1;
         end;

         function initSort(rowNames)
            sort,revSort,move={},{},{};
            for rowNum,rowName in pairs(rowNames) do
                   sort[rowNum]=rowName;
                   revSort[rowName]=rowNum;
            end;
          end;

         function moveRow(rowName,moveY)
                  local onclick=revSort[rowName];
                  if moveY<0 then
                      near=onclick-1;                                   
                  elseif moveY>0 then
                      near=onclick+1;
                  end
                  local rowNear=sort[near];  
                  local senderOnclick=document:getElementsByName(rowName);
                  local senderNear=document:getElementsByName(rowNear);
                  transition:setStopListener(senderOnclick,unlock);
                  transition:setStopListener(senderNear,unlock);
                  transition:setStartListener(senderOnclick,lock);
                  transition:setStartListener(senderNear,lock);
                  transition:translateY(senderOnclick,moveY,1);                 
                  transition:translateY(senderNear,-moveY,1);
                  sort[onclick],sort[near]=sort[near],sort[onclick]; 

                  revSort[rowName],revSort[rowNear]=revSort[rowNear],revSort[rowName];
         end;


------------------------初始化排序--------------------------------------
         --参数:需要排序的控件名称,在table中的位置与初始位置需相同
         initSort({"div1","div2","div3","div4"});

------------------------针对该页面调用排序-----------------------------------------       
          
         local y=0;

         function clickFun(argument,sender)
            y=y+argument["y"];
            alert(y);
            local rowName=sender:getPropertyByName("name");
            local position=revSort[rowName];              
            local moving=0;
            for i,v in pairs(move) do
                moving=moving+move[v]                                
            end;                    
          --以下是向下移动的代码
               if y>=30 and position~=4 and moving==0 then   
                  moveRow(rowName,60);
                  y=0;  
                end;          
          --以下是向上移动的代码
                if y<=-30 and  position~=1 and moving==0 then
                  moveRow(rowName,-60);
                  y=0;                  
                 end;           
           end;


---------------------------设置监听-------------------------------
            local div2 = document:getElementsByTagName("div2");
            gesture:setDragListener(div2, clickFun);

 

2.页面部分(样式略)

    <body name="body">
    <div class="div_test1" name ="div1" border="0">
         <label>row1</label>
    </div>
    <div class="div_test2" name ="div2" border="0">
         <label>row2</label>
    </div>
    <div class="div_test3" name ="div3" border="0">
         <label>row3</label>
    </div>
    <div class="div_test4" name ="div4" border="0">
          <label>row4</label>
    </div>
    </body>

行排序的逻辑,布布扣,bubuko.com

行排序的逻辑

标签:class   tar   get   strong   art   c   

原文地址:http://www.cnblogs.com/weiwangnuanyang/p/3709821.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!