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上。 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM