cx-cocos/cx-framework3.1/cx/scripts/cxui.safearea.ts
2021-06-07 15:13:32 +08:00

39 lines
774 B
TypeScript

import {_decorator, Component, Widget, UITransform, CCInteger} from 'cc';
const {ccclass, property} = _decorator;
@ccclass('cxui.safearea')
class CxuiSafearea extends Component
{
@property
private safeHeight = 170;
@property
private safeWidgetTop = 0;
@property
private safeWidgetBottom = 0;
onLoad ()
{
if (cx.os.native && !cx.os.android && cx.sh/cx.sw > 1.8)
{
if (this.safeHeight)
{
var uiTransform = this.node.getComponent(UITransform);
uiTransform?.setContentSize(uiTransform.width, this.safeHeight);
}
if (this.safeWidgetTop || this.safeWidgetBottom)
{
var widget = this.node.getComponent(Widget);
if (widget)
{
widget.top = this.safeWidgetTop;
widget.bottom = this.safeWidgetBottom;
}
}
}
}
}