在标签模板之间的离子滑动 [英] Ionic sliding between tabs template

查看:236
本文介绍了在标签模板之间的离子滑动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我下载了Ionic tabs模板。我玩了一会儿,我想知道如何添加一个滑动功能,可以在标签之间导航。在这种情况下,我想滑动动画和平滑过渡,而不是突然的标签切换。

I downloaded Ionic tabs template. I played around with it for a while and am wondering how to add a sliding function that can navigate between tabs. In this case, I want to slide with animations and a smooth transition, not a sudden tab switch.

我在Ionic Docs上看到。

I saw on Ionic Docs. It has this slide box feature.

    <ion-slide-box on-slide-changed="slideHasChanged($index)">
       <ion-slide>
           <div class="box blue"><h1>BLUE</h1></div>
       </ion-slide>
       <ion-slide>
          <div class="box yellow"><h1>YELLOW</h1></div>
       </ion-slide>
       <ion-slide>
             <div class="box pink"><h1>PINK</h1></div>
       </ion-slide>
    </ion-slide-box>

但我使用Ionic的标签模板

But then I am using tabs template from Ionic

<ion-tabs>
    <ion-tab>
        <ion-nav-view>
        </ion-nav-view>
    </ion-tab>


我如何将这些结合在一起?

Thank you!

谢谢!

推荐答案



首先,您需要在app.js的标签中添加控制器:

firstly, you need to add controller to your tab in app.js:

.state('tab', {
    url: '/tab',
    abstract: true,
    controller: 'TabsCtrl',
    templateUrl: 'views/base/tabs.html'
})

swipe-left,on-swipe-right attr和类:'active-tab - {{activeTab}}'到你的离子选项卡,'nav-tab-0'为你的第一个离子导航视图。

then, you need to modify your tabs.html with on-swipe-left, on-swipe-right attr and classes: 'active-tab-{{ activeTab }}"' to your ion-tabs and 'nav-tab-0' for you first ion-nav-view . Last number have to increase in next ion-nav-views.

因此,您的tabs.html应该如下所示:

So your tabs.html should look like this:

<ion-tabs class="tabs-icon-only tabs-color-active-positive active-tab-{{ activeTab }}" on-swipe-left="onSwipeLeft()" on-swipe-right="onSwipeRight()">

<ion-tab title="Notifications" icon-off="ion-flag" icon-on="ion-flag" ui-sref="tab.notifications">
    <ion-nav-view name="tab-notifications" class="nav-tab-0"></ion-nav-view>
</ion-tab>

<ion-tab title="Profile" icon-off="ion-person" icon-on="ion-person" ui-sref="tab.profile">
    <ion-nav-view name="tab-profile" class="nav-tab-1"></ion-nav-view>
</ion-tab>

<ion-tab title="Home-Map" icon-off="ion-map" icon-on="ion-map" ui-sref="tab.home_map">
    <ion-nav-view name="tab-home-map" class="nav-tab-2"></ion-nav-view>
</ion-tab>

<ion-tab title="Home-List" icon-off="ion-ios-list" icon-on="ion-ios-list" ui-sref="tab.home_list">
    <ion-nav-view name="tab-home-list" class="nav-tab-3"></ion-nav-view>
</ion-tab>

<ion-tab title="Create" icon-off="ion-plus-round" icon-on="ion-plus-round" ui-sref="tab.create_event">
    <ion-nav-view name="tab-create-event" class="nav-tab-4"></ion-nav-view>
</ion-tab>
</ion-tabs>

下一步是填充你的控制器。在这里,你需要有在你的导航中的状态名称表。
我的代码:

Next step is to fill you controller. Here you need to have to table of states names in order in your nav. Heres my code:

    $scope.tabList = [
        'tab.notifications',
        'tab.profile',
        'tab.home_map',
        'tab.home_list',
        'tab.create_event'
    ];

    $scope.onSwipeLeft = function() {
        for(var i=0; i < $scope.tabList.length; i++) {
            if ($scope.tabList[i] == $state.current.name && i != $scope.tabList.length){
                $state.go($scope.tabList[i+1]);
                break;
            }
        }
    };

    $scope.onSwipeRight = function() {
        for(var i=0; i < $scope.tabList.length; i++) {
            if ($scope.tabList[i] == $state.current.name && i != 0){
                $state.go($scope.tabList[i-1]);
                break;
            }
        }
    };

    $scope.$on('$ionicView.enter', function() {
        for(var i=0; i < $scope.tabList.length; i++) {
            if ($scope.tabList[i] == $state.current.name){
                $scope.activeTab = i;
                break;
            }
        }
    });

最后,这是动画和hidding离子导航视图,所有你可以在你的scss这样的文件:

Last this is the animation and hidding ion-nav-views, all that you can do in your scss files like this :

.tab-content {
    display: block;
    opacity: 0;
    @include transition-property('left, right');
    @include transition-duration(.3s);
}

$tabs-count: 5;

@for $i from 0 through $tabs-count {
    @for $j from 0 through $tabs-count {
        .active-tab-#{$i} {
            @if $i == $j {
                .nav-tab-#{$j} {
                    opacity: 1;
                    left: 0 !important;
                    right: 0 !important;
                }
            }
            @if $i > $j {
                .nav-tab-#{$j} {
                    left: -100%;
                    right: 100%;
                }
            }
            @if $i < $j {
                .nav-tab-#{$j} {
                    left: 100%;
                    right: -100%;
                }
            }
        }
    }
}


$ b b

所有这些都使它工作原生标签应用程序。
我希望我帮助,
这个解决方案非常适合我。

So all that togather make it works like native tab app. I hope I helped, This solutions works great for me.

这篇关于在标签模板之间的离子滑动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆