cocos学习-PageView

PageView可以实现分页视图,通过设置当中的属性和事件,可以实现不同的效果(自动翻页、翻页效果)

属性:

content:放视图的地方

Size Mode:

页面的大小类型,目前只有unidied(每个页面大小统一)和free(每个页面大小自定)

direction:控制视图是水平滚的还是垂直滚的

Scroll Threshold:拖拽当前的视图超过一定百分比可以自动切换到下一个视图

AutoPageTurningThreshold:通过滑动的开始时间结束时间和滑动距离计算出速度,如果速度太快(超过规定的临界值),就会自动翻页

Inertia:是否开启滚动惯性

Brake:惯性系数,0是开始滚动后永不停止,1是直接停止。

Elastie:是否允许滚动内容超过边界,开启后比如下滑到底部后超出并会反弹一下           

Bounce Duration:回弹持续时间,0表示会立刻反弹 

Indicator:表示切换到哪个页面的组件

           

PageTurning Speed:每个页面翻动需要的时间

PageTurning EventTiming:设置 PageView、PageTurning 事件的发送时机 

PageEvents:页面视图的事件回调函数。

在制作像背包这样的页面的时候,可以在page下面添加一个layout组件:

pageView的方法基本都继承自scrollview:

如果想要滚动到某个特定的页面,可以使用scrollToPage(第几页,滚动时间)

挂载后,花0.1秒滚动到第二个页面(从0开始)
this.myPageView.scrollToPage(1,0.1);

 几种设置color的办法:

 //获得随机rgb并set
            let tmp = cc.instantiate(this.item);
            let rgb_r = Math.ceil(Math.random()*255);
            let rgb_g = Math.ceil(Math.random()*255);
            let rgb_b = Math.ceil(Math.random()*255);
            tmp.color = tmp.color.setR(rgb_r);
            tmp.color = tmp.color.setG(rgb_g);
            tmp.color = tmp.color.setB(rgb_b);
//使用new cc.Color ()设置
            let tmp = cc.instantiate(this.item);
            let rgb_r = Math.ceil(Math.random()*255);
            let rgb_g = Math.ceil(Math.random()*255);
            let rgb_b = Math.ceil(Math.random()*255);
            // tmp.color = tmp.color.setR(rgb_r);
            // tmp.color = tmp.color.setG(rgb_g);
            // tmp.color = tmp.color.setB(rgb_b);
            //let tmpC = new cc.Color().fromHEX('#BF7F7F');
            let tmpC = new cc.Color(rgb_r,rgb_g,rgb_b);
            tmp.color = tmpC;
//使用new cc.Color().fromHEX('')
            //let tmpC = new cc.Color().fromHEX('#BF7F7F');
            let tmpC = new cc.Color(rgb_r,rgb_g,rgb_b);
            tmp.color = tmpC;

  • 5
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值