获取胶囊按钮的位置信息
想获取一下,胶囊按钮的位置,网上没找了找,自己封装一下吧
// 获取的胶囊的大小,位置
// 得到的结果和 widget 组件类似
getMenuButtonBoundingRect() {
if (cc.sys.platform === cc.sys.WECHAT_GAME) {
let systemInfo = wx.getSystemInfoSync();
let windowHeight = systemInfo.windowHeight;
let gameSize = cc.view.getVisibleSize();
let gameHeight = gameSize.height;
let ratio = gameHeight / windowHeight;
let rect = wx.getMenuButtonBoundingClientRect();
rect.width *= ratio;
rect.height *= ratio;
rect.left *= ratio;
rect.top *= ratio;
rect.bottom = gameSize.height - rect.bottom * ratio;
rect.right = gameSize.width - rect.right * ratio;
return rect;
} else {
return cc.rect();
}
}