Dunc 的回答非常好,但在 Ionic 的视图缓存方面效果不佳。
使用 $destroy 事件,它会在父视图被拆除时设置 $rootScope 变量。
然而,正如其他人评论的那样,当返回到需要标签的页面时,这个 $destroy 事件发生得太晚了。这会导致页面转换时出现延迟的跳跃行为。此外,直到延迟之后才会添加 ion-content .has-tabs 类,因此选项卡也会覆盖任何内容。
相反,我们应该在 Ionic 事件 beforeLeave 上重置,以确保转换的摘要循环及时获得变量变化。
同一个模板:
<ion-tabs ng-class="{'tabs-item-hide': $root.hideTabs}" class="tabs-icon-only">
<!-- tabs -->
</ion-tabs>
指令(同样基于 Dunc):
.directive('hideTabs', function($rootScope) {
return {
restrict: 'A',
link: function(scope, element, attributes) {
scope.$watch(attributes.hideTabs, function(value){
$rootScope.hideTabs = value;
});
scope.$on('$ionicView.beforeLeave', function() {
$rootScope.hideTabs = false;
});
}
};
});
用法一样——
<ion-view title="New Entry Form" hide-tabs='some-bool-expression'>
<!-- view content -->
</ion-view>
另外,如果您使用的是 SASS,如果您将其添加到您的 .scss 文件中,您可以获得一个不错的标签栏弹出过渡:
.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;
}
如果使用原生 CSS,请将 $tabs-height 替换为条形的高度。