Laya List翻页滚动方案 & List滚动源码解析

@author ixenos 2019-03-29

1.List翻页滚动方案

 /**
* 计算下一页的起始索引, 不足时补足
* @param direction 0 for pre, 1 for nex , @author ixenos 2019-03-29
*/
private function btnScrollControl(direction:int=0):void{
if(direction==0){
var minusResult:int = list.startIndex - list.repeatX;
if(minusResult>=0){
list.tweenTo(minusResult);
}else{
list.tweenTo(0);
}
}else if(direction==1){
var plusResult:int = list.startindex + list.repeatX;
if(plusResult<=list.array.length-1){
list.tweenTo(plusResult);
}else{
list.tweenTo(list.array.length-1);
}}
}

2.List滚动源码解析

1) scrollTo和tweenTo都需要list本身自带滚动条
 /**
* <p>滚动列表,以设定的数据索引对应的单元格为当前可视列表的第一项。</p>
* @param index 单元格在数据列表中的索引。
*/
public function scrollTo(index:int):void {
if (_scrollBar) {
var numX:int = _isVertical ? repeatX : repeatY;
_scrollBar.value = Math.floor(index / numX) * _cellSize;
} else {
startIndex = index;
}
}
2) tweenTo内部是对scrollBar进行tween
 /**
* <p>缓动滚动列表,以设定的数据索引对应的单元格为当前可视列表的第一项。</p>
* @param index 单元格在数据列表中的索引。
* @param time 缓动时间。
* @param complete 缓动结束回掉
*/
public function tweenTo(index:int, time:int = 200, complete:Handler = null):void {
if (_scrollBar) {
var numX:int = _isVertical ? repeatX : repeatY;
Tween.to(_scrollBar, {value: Math.floor(index / numX) * _cellSize}, time, null, complete, 0, true);
} else {
startIndex = index;
if (complete) complete.run();
}
}
3) scrollBar之于List
 public function set scrollBar(value:ScrollBar):void {
if (_scrollBar != value) {
_scrollBar = value;
if (value) {
_isVertical = _scrollBar.isVertical;
addChild(_scrollBar);
_scrollBar.on(Event.CHANGE, this, onScrollBarChange);
}
}
}
 /**
* @private
* 滚动条的 <code>Event.CHANGE</code> 事件侦听处理函数。
*/
protected function onScrollBarChange(e:Event = null):void {
runCallLater(changeCells);
var scrollValue:Number = _scrollBar.value;
var lineX:int = (_isVertical ? this.repeatX : this.repeatY);
var lineY:int = (_isVertical ? this.repeatY : this.repeatX);
var scrollLine:int = Math.floor(scrollValue / _cellSize); if (!cacheContent) {
var index:int = scrollLine * lineX;
var num:int = 0;
if (index > _startIndex) {
num = index - _startIndex;
var down:Boolean = true;
var toIndex:int = _startIndex + lineX * (lineY + 1);
_isMoved = true;
} else if (index < _startIndex) {
num = _startIndex - index;
down = false;
toIndex = _startIndex - 1;
_isMoved = true;
} for (var i:int = 0; i < num; i++) {
if (down) {
var cell:Box = _cells.shift();
_cells[_cells.length] = cell;
var cellIndex:int = toIndex + i;
} else {
cell = _cells.pop();
_cells.unshift(cell);
cellIndex = toIndex - i;
}
var pos:Number = Math.floor(cellIndex / lineX) * _cellSize;
_isVertical ? cell.y = pos : cell.x = pos;
renderItem(cell, cellIndex);
}
_startIndex = index;
changeSelectStatus();
} else {
num = (lineY + 1);
if (_createdLine - scrollLine < num) {
_createItems(_createdLine, lineX, _createdLine + num);
renderItems(_createdLine * lineX, 0);
_createdLine += num;
}
} var r:Rectangle = _content._style.scrollRect;
if (_isVertical) {
r.y = scrollValue - _offset.y;
r.x = -_offset.x;
} else {
r.y = -_offset.y;
r.x = scrollValue - _offset.x;
}
_content.scrollRect = r;
}
 

Laya List翻页滚动方案 & List滚动源码解析的更多相关文章

  1. 百度智能手环方案开源(含源码,原理图,APP,通信协议等)

    分享一个百度智能手环开源项目的设计方案资料. 项目简介 百度云智能手环的开源方案是基于Apache2.0开源协议,开源内容包括硬件设计文档,原理图.ROM.通讯协议在内的全套方案,同时开放APP和云服 ...

  2. Laya Timer原理 & 源码解析

    Laya Timer原理 & 源码解析 @author ixenos 2019-03-18 16:26:38 一.原理 1.将所有Handler注册到池中 1.普通Handler在handle ...

  3. [源码解析] 深度学习分布式训练框架 horovod (11) --- on spark --- GLOO 方案

    [源码解析] 深度学习分布式训练框架 horovod (11) --- on spark --- GLOO 方案 目录 [源码解析] 深度学习分布式训练框架 horovod (11) --- on s ...

  4. 简易数据分析 10 | Web Scraper 翻页——抓取「滚动加载」类型网页

    这是简易数据分析系列的第 10 篇文章. 友情提示:这一篇文章的内容较多,信息量比较大,希望大家学习的时候多看几遍. 我们在刷朋友圈刷微博的时候,总会强调一个『刷』字,因为看动态的时候,当把内容拉到屏 ...

  5. iOS仿抖音节拍界面、Swift,MVVM架构完整项目、日历demo、滚动切换分类等源码

    iOS精选源码 在Object-C中学习数据结构与算法之排序算法 日历-基本功能都有的日历 选择日期 上下月 动画 仿抖音卡节拍界面 垂直.水平方向皆可滚动.header悬浮的列表视图 Auto La ...

  6. Android DiskLruCache 源码解析 硬盘缓存的绝佳方案

    一.概述 依旧是整理东西,所以近期的博客涉及的东西可能会比较老一点,会分析一些经典的框架,我觉得可能也是每个优秀的开发者必须掌握的东西:那么对于Disk Cache,DiskLruCache可以算佼佼 ...

  7. 滴滴插件化方案 VirtualApk 源码解析

    那么其中的难点很明显是对四大组件支持,因为大家都清楚,四大组件都是需要在AndroidManifest中注册的,而插件apk中的组件是不可能预先知晓名字,提前注册中宿主apk中的,所以现在基本都采用一 ...

  8. LiteDB源码解析系列(2)数据库页详解

    在这一篇里,我将用图文的方式展示LiteDB中页的结构及作用,内容都是原创,在描述的过程中有不准确的地方烦请指出. 1.LiteDB页的技术工作原理 LiteDB虽然是单个文件类型的数据库,但是数据库 ...

  9. ------ 开源软件 Tor(洋葱路由器,构建匿名网络的方案之一)源码分析——主程序入口点(二)------

    ---------------------------------------------------------- 第二部分仅考察下图所示的代码片段--configure_backtrace_han ...

随机推荐

  1. 绘制复杂的原理图元件和pcb封装库用于cadence(一)

    绘制TI公司的TPS53319电源芯片封装 由于产品设计需要大电流电源供电,选用TI公司TPS53319电源芯片通过cadence软件进行电路设计,但是TI公司所提供的封装格式为CAD File(.b ...

  2. 借助Code Splitting 提升单页面应用性能

    近日的工作集中于一个单页面应用(Single-page application),在项目中尝试了闻名已久的Code splitting,收获极大,特此分享. Why we need code spli ...

  3. WebService学习之旅(五)基于Apache Axis2发布第一个WebService

    上篇博文介绍了如何將axis2 webservice引擎安装到Web容器中,本节开始介绍如何基于apache axis2发布第一个简单的WebService. 一.WebService服务端发布步骤 ...

  4. uvm_reg——寄存器模型(三)

    uvm_reg 是uvm_reg_field , 包含所有uvm_reg_field 所有的函数.

  5. springMVC中jackson的使用(包含JsonFormat 时间格式)

    前台使用ajax,后台 springMVC Java下常见的Json类库有Gson.JSON-lib和Jackson等,Jackson相对来说比较高效,在项目中主要使用Jackson进行JSON和Ja ...

  6. (转)MyBatis框架的学习(五)——一对一关联映射和一对多关联映射

    http://blog.csdn.net/yerenyuan_pku/article/details/71894172 在实际开发中我们不可能只是对单表进行操作,必然要操作多表,本文就来讲解多表操作中 ...

  7. UVA 10817 - Headmaster's Headache(三进制状压dp)

    题目:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=20&pag ...

  8. 快学UIautomator之uiautomatorhelp使用

    1.先下载uiautomatorhelp插件 2.把uiautomatorhelp.java包放到自己的项目中 3.项目中引入uiautomatorhelp插件 4.在项目中设置一个main方法,引入 ...

  9. CPP-基础:C++的new int()与new int[]

    编写一个List类: class List { int length; //列表长度 int* lpInt; //列表指针 List(int size); ~List(); } List::List( ...

  10. Spring持久化之MyBatis

    MyBatis是一个优秀的轻量级持久化框架,本文主要介绍MyBatis与Spring集成的配置与用法. 1. Spring MyBatis配置 1.1 添加Maven依赖 在pom.xml文件里添加m ...