博客
关于我
微信小程序_自定义tabbar实现中间图标突出效果(附带wx.hideTabBar不生效的bug解决方案)
阅读量:664 次
发布时间:2019-03-15

本文共 2276 字,大约阅读时间需要 7 分钟。

github传送门https://github.com/SuRuiGit/wxapp-customTabbar

在这里插入图片描述
第一步:找到项目中的tabbarComponent目录,拷贝到你的工程中,然后将tabbarComponent->icon图标替换成你自己的tabbar图片(建议把tabbarComponent目录与pages同级)
在这里插入图片描述
第二步:到app.json中配置tabBar,如果tabbar中间的按钮是跳到二级页面,就不要配置在tabBar的list中,如果配置了,中间的按钮点击是无效的,要注意
在这里插入图片描述
第三步:在app.js的onLaunch方法中调用hidetabbar()自己封装一下,代码如下,隐藏系统自带的tabBar直接写wx.hideTabBar在安卓8.0有bug,并且在每一个用到tabbar的js文件中的onReady和onShow中调用一下app.hidetabbar(),调用getSystemInfo()方法获取设备信息,主要是为了适配iPhone X,这个方法在下面会给出
在这里插入图片描述

//自己对wx.hideTabBar的一个封装hidetabbar() {       wx.hideTabBar({         fail: function() {           setTimeout(function() {    // 做了个延时重试一次,作为保底。          wx.hideTabBar()        }, 500)      }    });  },getSystemInfo: function() {       let t = this;    wx.getSystemInfo({         success: function(res) {           t.globalData.systemInfo = res;      }    });  },

第四步:在app.js中的globalData中加入自定义tabbar和systemInfo的参数,再加入一个方法给tabBar.list配置中的页面使用,代码如下

editTabbar: function() {     let tabbar = this.globalData.tabBar;  let currentPages = getCurrentPages();  let _this = currentPages[currentPages.length - 1];  let pagePath = _this.route;  (pagePath.indexOf('/') != 0) && (pagePath = '/' + pagePath);  for (let i in tabbar.list) {       tabbar.list[i].selected = false;    (tabbar.list[i].pagePath == pagePath) && (tabbar.list[i].selected = true);  }  _this.setData({       tabbar: tabbar  });},globalData: {     systemInfo: null,//客户端设备信息  tabBar: {       "backgroundColor": "#ffffff",    "color": "#979795",    "selectedColor": "#1c1c1b",    "list": [      {           "pagePath": "/page/index/index",        "iconPath": "icon/icon_home.png",        "selectedIconPath": "icon/icon_home_HL.png",        "text": "首页"      },      {           "pagePath": "/page/myRelease/index",        "iconPath": "icon/icon_release.png",        "isSpecial": true,        "text": "发布"      },      {           "pagePath": "/page/mine/index",        "iconPath": "icon/icon_mine.png",        "selectedIconPath": "icon/icon_mine_HL.png",        "text": "我的"      }    ]   }}

第五步:在tabBar的list中配置的页面的.js文件的data中加入tabbar:{},并在onload方法中调用app.editTabbar();

第六步:在tabBar的list中配置的页面的.json文件中加入"usingComponents": { “tabbar”: “…/…/tabbarComponent/tabbar” }在.wxml文件中加入

第七步:修改tabbarComponent->tabbar.js->data中的代码,代码截图如下

在这里插入图片描述

到此我们就实现了突出效果,首先感谢大佬提供的轮子,如果侵权,请联系我,我会第一时间删除本文章

转载地址:http://vtemz.baihongyu.com/

你可能感兴趣的文章
NN&DL4.3 Getting your matrix dimensions right
查看>>
NN&DL4.7 Parameters vs Hyperparameters
查看>>
NN&DL4.8 What does this have to do with the brain?
查看>>
nnU-Net 终极指南
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
NO 157 去掉禅道访问地址中的zentao
查看>>
no available service ‘default‘ found, please make sure registry config corre seata
查看>>
No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
查看>>
no connection could be made because the target machine actively refused it.问题解决
查看>>
No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
查看>>
No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
查看>>
No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
查看>>
No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
查看>>
No mapping found for HTTP request with URI [/logout.do] in DispatcherServlet with name 'springmvc'
查看>>
No module named 'crispy_forms'等使用pycharm开发
查看>>
No module named 'pandads'
查看>>
No module named cv2
查看>>
No module named tensorboard.main在安装tensorboardX的时候遇到的问题
查看>>
No module named ‘MySQLdb‘错误解决No module named ‘MySQLdb‘错误解决
查看>>