| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- const {ccclass, property} = cc._decorator;
- const LeftPadding = 65;
- const RightPadding = 65;
- /**
- * 刘海屏适配
- * @author 薛鸿潇
- */
- @ccclass
- export default class BangsFit extends cc.Component {
- @property({displayName: '是否适配特殊节点'})
- private isFitSpecialNode = false;
- @property({displayName: '是否适配特殊节点', visible(){return this.isFitSpecialNode}})
- private offset = 80;
- onLoad() {
- this._AdaptLeftAndRight();
- }
- start()
- {
- }
- /*============================================================================================================*/
- /**
- */
- /*============================================================================================================*/
- _AdaptLeftAndRight() {
- let widget = this.node.getComponent(cc.Widget);
- if (!widget) return;
- let is_big = this.IsBigScreenRatio();
- if (is_big) {
- if(this.isFitSpecialNode)
- {
- if(widget.isAlignTop)
- {
- let add = Math.round((this.GetWinHeightWidthRatio() * this.offset)/1.86);
- widget.top = widget.top + add;
- }
- if(widget.isAlignBottom)
- {
- let add = Math.round((this.GetWinHeightWidthRatio() * this.offset)/1.86);
- widget.bottom = widget.bottom + add;
- }
-
- }else{
- widget.top = LeftPadding;
- }
-
- // widget.bottom = RightPadding;
- }
- }
- /**
- * @returns 是宽屏
- */
- IsBigScreenRatio() {
- return this.GetWinHeightWidthRatio() >= 1.86;
- }
- /**
- * @returns 屏幕比率
- */
- GetWinHeightWidthRatio() {
- let ratio = cc.winSize.height >= cc.winSize.width ? (cc.winSize.height / cc.winSize.width) : (cc.winSize.width / cc.winSize.height);
- return ratio;
- }
- }
|