首页 技术 正文
技术 2022年11月15日
0 收藏 447 点赞 4,886 浏览 1033 个字

最近在公司开发游戏,使用cocos creator做微信小游戏,遇到一个很恶心的问题,如图:

如图所示,微信的广告位被iphonex的底部bar给弹出了一点位置,没有靠在底部。

在这里不得不吐槽一下微信的小程序接口还有个恶心的地方,那就是他的广告style没有bottom,right属性,使得置底部必须使用算法计算。也就是winsize.height-广告高度(realheight),居中是winsize.width-广告宽度/2。

而就算如此,在Android和iphone普通手机上是没有适配问题的,完全居中靠底,而一到高贵的iPhonex上,就会出现广告位一会儿靠底部,一会又被底部黑色bar顶出一点位置,要解决这个蛋疼的问题,如下解决:

     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;
}
}

注意几点:

  1. 创建banner的默认位置不需要修改,反正也没用
  2. 在onresize中重置style来改变位置
  3. 使用realwidth和realheight作为相对位移(这两项必须是在banner已经创建完成的情况下)
  4. left和top都加上0.1,不加就会被iphonex该死的底部bar给顶上去,而且时而顶上去,时而又是正常,至今不知道为什么
  5. onresize之后再使用show方法将广告banner给show出来
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,494
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,908
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,740
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,496
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,133
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,297