Ionic Framework隐藏特定页面上的选项卡

时间:2015-10-13 21:04:08

标签: ionic-framework ionic

我正在使用离子框架,我已经创建了一个新的标签应用程序。

我需要做的是将一个页面作为默认页面或主页面没有选项卡,然后让所有其他页面正常显示选项卡。

像目标网页一样。

我该怎么做?

4 个答案:

答案 0 :(得分:8)

<强> Plunker Demo

首先在 $stateProvider 中为着陆或默认页面定义单独的$stateProvider [我认为您已经为其他页面定义了app.js。“ app.js 文件应该是这样的,

<强> app.js

var app = angular.module('myApp', ['ionic']);

app.config(function($stateProvider, $urlRouterProvider) {
  $stateProvider
    .state('tabs', {
      url: '/tab',
      controller: 'TabsCtrl',
      templateUrl: 'tabs.html'
    })
    .state('tabs.home', {
      url: '/home',
      views: {
        'home-tab': {
           controller: 'homeCtrl',
          templateUrl: 'home.html'
        }
      }
    })  
    .state('tabs.settings', {
      url: '/settings',
      views: {
        'settings-tab': {
           controller: ' signOutCtrl',
          templateUrl: 'settings.html'
        }
      }
    });
     $stateProvider
        .state('landing', {
            url: '/landing',
            controller: 'landingCtrl',
            templateUrl: 'landing.html'
    });

  $urlRouterProvider.otherwise('/landing');
});

还为标签创建一个html页面。

<强> tabs.html

<ion-view title="Home">
    <ion-nav-buttons side="left">
        <button class="button button-icon button-clear ion-navicon" ng-click="openMenu()"></button>
    </ion-nav-buttons>
    <ion-tabs class="tabs-icon-top tabs-positive">
        <ion-tab title="{{tab1Title}}" icon="ion-home" href="#/tab/home">
            <ion-nav-view name="home-tab"></ion-nav-view>
        </ion-tab>
        <ion-tab title="{{tab2Title}}" icon="ion-gear-a" href="#/tab/settings">
            <ion-nav-view name="settings-tab"></ion-nav-view>
        </ion-tab>
        <ion-tab title="{{tab3Title}}" href="#/landing" icon="ion-log-out">
        </ion-tab>
    </ion-tabs>
</ion-view>

您还需要使用<ion-nav-bar> landing 页面中隐藏hide-nav-bar="true "

<强> landing.html上

<ion-view hide-nav-bar="true ">
    <ion-nav-buttons side="left">
        <button class="button button-icon button-clear ion-navicon" ng-click="openMenu()"></button>
    </ion-nav-buttons>
    <ion-content padding="true">
        <h1 style="text-align: center;">Welcome To Landing Page</h1>
        <a class="button icon-right ion-chevron-right button-calm" ng-click="open()">Lets Go</a>
    </ion-content>
</ion-view>

答案 1 :(得分:8)

在最近的离子版本中,通过设置

可以轻松实现
$ionicTabsDelegate.showBar(false);

示例代码:

.directive('hideTabs', function($rootScope, $ionicTabsDelegate) {
  return {
    restrict: 'A',
    link: function($scope, $el) {
      $scope.$on("$ionicView.beforeEnter", function () {
        $ionicTabsDelegate.showBar(false);
      });
      $scope.$on("$ionicView.beforeLeave", function () {
        $ionicTabsDelegate.showBar(true);
      });
    }
  };
})

SOURCE

答案 2 :(得分:7)

尝试这个很简单

<!-- in your tabs.html add this ng-class -->
    <ion-tabs ng-class="{'tabs-item-hide': hideTabs}">

    </ion-tabs>

    <!-- add 'hide-tabs'in your view where you want to hide the tabs -->
    <ion-view hide-tabs> 

    </ion-view>

    // in your app.js add a directive
    .directive('hideTabs', function($rootScope) {
        return {
            restrict: 'A',
            link: function($scope, $el) {
                $rootScope.hideTabs = true;
                $scope.$on('$destroy', function() {
                    $rootScope.hideTabs = false;
                });
            }
        };
    })

答案 3 :(得分:2)

试试这是一个简单的例子......

步骤1) 默认情况下,默认应用在标签栏中有三个标签,即主页关于联系。假设我们想要在用户导航到about选项卡时隐藏选项卡栏。为此,我们需要更改您可以在

找到的about.ts文件

<强> about.ts

export class AboutPage {
  tabBarElement: any;
  constructor(public navCtrl: NavController) {
    this.tabBarElement = document.querySelector('.tabbar.show-tabbar');
  }

  ionViewWillEnter() {
    this.tabBarElement.style.display = 'none';
  }

  ionViewWillLeave() {
    this.tabBarElement.style.display = 'flex';
  }

第2步) about.html

<ion-header>
  <ion-navbar>
       <ion-buttons left>
        <button ion-button icon-only (click)="takeMeBack()">
           <ion-icon name="arrow-back"></ion-icon>
       </button>
     </ion-buttons>
    <ion-title>
      About
    </ion-title>
  </ion-navbar>
</ion-header>

<ion-content padding>
  This is About Page Tab bar is Hidden.
</ion-content>
Step 3)

<强> about.ts

 takeMeBack() {
    this.navCtrl.parent.select(0);
  }