本文为大家分享了ionic隐藏tabs的方法,供大家参考,具体内容如下
1.
<ion-tabs ng-class="{"tabs-item-hide": $root.hideTabs}"><!-- tabs --></ion-tabs>
2.
在该控制器下加上.directive:
var module = angular.module("app.directives", []);module.directive("showTabs", function ($rootScope) {return {restrict: "A",link: function ($scope, $el) {$rootScope.hideTabs = false;}};}).directive("hideTabs", function ($rootScope) {return {restrict: "A",link: function ($scope, $el) {$rootScope.hideTabs = true;}};})
3.
在html页面中引用hide-tabs
<ion-view title="New Entry Form" hide-tabs><!-- view content --></ion-tabs>
4.
当页面返回主页面时,需要再次显示tabs,则需要在该控制器中加上(主要是解决android上tabs还是隐藏的问题):
$scope.$on("$ionicView.enter", function () {// 显示 tabs$rootScope.hideTabs = false;});
5.
我用的是tabs-top,还遇到的一个问题是:<ion-content>的一部分内容会被隐藏;解决办法:
再次修改directive.js里边的内容,不再使用showTabs:
.directive("hideTabs", function ($rootScope) {return {restrict: "A",link: function (scope, element, attributes) {scope.$on("$ionicView.beforeEnter", function () {scope.$watch(attributes.hideTabs, function (value) {$rootScope.hideTabs = value;});});scope.$on("$ionicView.beforeLeave", function () {$rootScope.hideTabs = false;});}};})
来个总结吧,相对于tabs用法,如果是在底部的话,上边的那些不会有什么太大的问题。但如果是用在顶部的话,涉及到content,会遇到一点问题。
其实可以考虑使用ionic上的<ion-slide>来代替<ion-tabs>,不管是与其它页面的滑动效果,还是slide页面的滑动效果都会很大的提升,特别是在android上。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。