Cocos 3.8 scrollView 内容不足时 依然显示 scrollView bar

import { _decorator, Node, UITransform, Component, CCFloat, Widget } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('Kit_otherSizeBind')
// 监听一个节点的大小变化,并进行绑定
export default class Kit_otherSizeBind extends Component {
    @property(Node)
    bindNode:Node = null;

    @property(CCFloat)
    max_width:number = 0;

    @property(CCFloat)
    max_height:number = 0;

    @property(CCFloat)
    height_dis:number = 1;

    ui_transform:UITransform = null;

    start(): void {
        if(this.bindNode){
            let widget = this.node.getComponent(Widget);
            if(widget){
                widget.enabled = false;
            }
            this.ui_transform = this.node.getComponent(UITransform);
            if(!this.max_width){
                this.max_width = this.ui_transform.width;
            }
            if(!this.max_height){
                this.max_height = this.ui_transform.height;
            }
            this.bindNode.on(Node.EventType.SIZE_CHANGED, this.onSizeChanged, this);
            this.updateSize();
        }
    }

    onSizeChanged(event) {
        this.updateSize()
    }

    updateSize(){
        let { width, height } = this.bindNode.getComponent(UITransform).contentSize;
        this.ui_transform.width = width > this.max_width ? this.max_width : width;
        if(this.height_dis){
            this.ui_transform.height = (height > this.max_height ? this.max_height : height) - this.height_dis;
        }else{
            this.ui_transform.height = height > this.max_height ? this.max_height : height;
        }
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值