var testLayer = cc.Layer.extend({
ctor : function(){
this._super();
this.init();
return true;
},
init : function(){
var csv = new cc.ScrollView();
csv.setDirection(cc.SCROLLVIEW_DIRECTION_HORIZONTAL);
csv.setTouchEnabled(true);
csv.setBounceable(true);
csv.setViewSize(cc.size(500, 400));
csv.setAnchorPoint(cc.p(0, 0));
csv.x = 0;
csv.y = 0;
this.addChild(csv);
csv.setContentSize(cc.size(500, 400));
var layer = new cc.LayerColor();
layer.setColor(cc.color(0, 255, 255));
csv.setContainer(layer)
for(var i = 0; i < 8; i++){
var widthList = new cc.LayerColor();
widthList.attr({
x : i * 100 + (i + 1) * 20,
y : 0,
width : 100,
height : 500,
color : colorList[i]
});
csv.addChild(widthList);
}
var childWidth = 0;
for(var i = 0; i < csv.getContainer().children.length; i++){
childWidth += csv.getContainer().children[i].width + 20;
}
cc.log("【打印】childWidth:",childWidth,csv.children.length);
csv.setContentSize(cc.size(childWidth, 400));
cc.log("【scrollView】打印:", csv.getContentSize().width, csv.getContentSize().height);
}
});
cc.scrollView基础用法
最新推荐文章于 2020-09-07 10:20:29 发布