微信小游戏广告位iphonex底部适配问题
最近在公司开发游戏,使用cocos creator做微信小游戏,遇到一个很恶心的问题,如图:
如图所示,微信的广告位被iphonex的底部bar给弹出了一点位置,没有靠在底部。
在这里不得不吐槽一下微信的小程序接口还有个恶心的地方,那就是他的广告style没有bottom,right属性,使得置底部必须使用算法计算。也就是winsize.height-广告高度(realheight),居中是winsize.width-广告宽度/2。
而就算如此,在Android和iphone普通手机上是没有适配问题的,完全居中靠底,而一到高贵的iPhonex上,就会出现广告位一会儿靠底部,一会又被底部黑色bar顶出一点位置,要解决这个蛋疼的问题,如下解决:
getWXFunction(name) {if(typeof(wx) == 'undefined' || wx == null) {return null;}return wx[name];}showBannerAd() {var wxFunc = this.getWXFunction('createBannerAd');if(typeof(wxFunc) != 'undefined' && wxFunc != null) {var phone = wx.getSystemInfoSync();console.log(phone);var w = phone.screenWidth / 2;var h = phone.screenHeight;let bannerAd = wxFunc({adUnitId: 'adunit-549b2e8b53ad8e21',style: {width: 300,//height:40,top: 0,left: 0}});bannerAd.onResize(function() {bannerAd.style.left = w - bannerAd.style.realWidth / 2 + 0.1;bannerAd.style.top = h - bannerAd.style.realHeight + 0.1;console.log(bannerAd);})bannerAd.show();return bannerAd;} else {return;}}注意几点:
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。

