本文為大家分享了ionic隱藏tabs的方法,供大家參考,具體內(nèi)容如下
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頁(yè)面中引用hide-tabs
<ion-view title="New Entry Form" hide-tabs> <!-- view content --></ion-tabs>
4.
當(dāng)頁(yè)面返回主頁(yè)面時(shí),需要再次顯示tabs,則需要在該控制器中加上(主要是解決android上tabs還是隱藏的問題):
$scope.$on('$ionicView.enter', function () { // 顯示 tabs $rootScope.hideTabs = false;}); 5.
我用的是tabs-top,還遇到的一個(gè)問題是:<ion-content>的一部分內(nèi)容會(huì)被隱藏;解決辦法:
再次修改directive.js里邊的內(nèi)容,不再使用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; }); } };}) 來個(gè)總結(jié)吧,相對(duì)于tabs用法,如果是在底部的話,上邊的那些不會(huì)有什么太大的問題。但如果是用在頂部的話,涉及到content,會(huì)遇到一點(diǎn)問題。
其實(shí)可以考慮使用ionic上的<ion-slide>來代替<ion-tabs>,不管是與其它頁(yè)面的滑動(dòng)效果,還是slide頁(yè)面的滑動(dòng)效果都會(huì)很大的提升,特別是在android上。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持武林網(wǎng)。
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注