有tabs的項目裏,進入子層級時,底部導航還一直存在,本人是要讓他只在首頁幾個界面存在,其餘的隱藏,在這裏用到了angularjs的指令,要完成這個步驟分爲三步:javascript
1.在標籤ion-tabs中添加:ng-class=」{‘tabs-item-hide’: $root.hideTabs}」,源碼以下:css
<ion-tabs class="tabs-icon-top" ng-class="{'tabs-item-hide': $root.hideTabs}"> //tabs </ion-tabs>
2.添加angularjs的指令,源碼以下:java
//app已經在其餘文件中指定,如var app = angular.module("starter",["ionic"]) angular.module('starter', ['ionic', 'starter.controllers', 'starter.services']) .directive('hideTabs', function ($rootScope,$location) { return { restrict: 'AE', link: function (scope, element, attributes) { scope.$on('$ionicView.beforeEnter', function () { scope.$watch(attributes.hideTabs, function (value) { $rootScope.hideTabs = value; if ($location.path() == '/main_tab/mian' || $location.path() == '/main_tab/mian') { //scope.$on('$ionicView.beforeLeave', function() { // $rootScope.hideTabs = false; //}); } }) }) } } })
//app已經在其餘文件中指定,如var app = angular.module("starter",["ionic"]) app.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; }); } }; });
3.三你想要隱藏的界面標籤 ion-view添加表達式hide-tabs=」true」,源碼以下:angularjs
//這是官網模板中的文件<ion-view hide-tabs="true" view-title="{{chat.name}}"> <ion-content class="padding"> <img ng-src="{{chat.face}}" style="width: 64px; height: 64px"> <p> {{chat.lastText}} </p> </ion-content></ion-view>
4.web
另外,若是要把效果搞得好看點,沒有什麼延遲現象,須要改動ionic.css文件,改動他須要用scss,這些內容前面也有介紹,改動地方以下:app
.tabs { -webkit-transition: all linear 0.2s; transition: all linear 0.2s; } .tabs-item-hide > .tabs{ -webkit-transition: all linear 0.2s; transition: all linear 0.2s; bottom: -$tabs-height; display: flex; }
上面內容在tabs.scss文件中!
ionic