class ScrollerPosition extends eui.UILayer{ private scroller:eui.Scroller; public listArray:Array<number> = []; constructor(){ super(); //创建一个列表 var list = new eui.List(); this.listArray = [1,2,3,4,5,6,7]; list.dataProvider = new eui.ArrayCollection(this.listArray); //创建一个scroller var scroller = new eui.Scroller(); scroller.height = 160; scroller.viewport = list; this.addChild(scroller); this.scroller = scroller; //https://developer.egret.com/cn/article/index/id/611 //需要在scroller添加到舞台上面之后再访问verticalScrollBar // scroller.verticalScrollBar.autoVisibility = false; // scroller.verticalScrollBar.visible = false; //创建一个按钮,点击后改变Scroller被动的位置 var btn = new eui.Button(); btn.x = 200; this.addChild(btn); btn.addEventListener(egret.TouchEvent.TOUCH_TAP,this.moveScroller,this); } protected createChildren(){ //初始化后改变被动的位置 this.scroller.viewport.validateNow(); this.scroller.viewport.scrollV = 40; } private moveScroller():void{ //点击按钮后改变被动的位置 var sc = this.scroller; sc.viewport.scrollV += 10; if((sc.viewport.scrollV + screen.height) > sc.viewport.contentHeight){ console.log("滚动到底部"); this.listArray.push(12,23,33,43,35,63,37); } //停止正在被动的动画 sc.stopAnimation(); } }