ionic隱藏tabs的方法_javascript技巧

來源:互聯網
上載者:User

本文為大家分享了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上。

以上就是本文的全部內容,希望對大家的學習有所協助,也希望大家多多支援雲棲社區。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.