在细分标签中滑动-Ionic 3 [英] Swipe through segment tabs - Ionic 3

查看:68
本文介绍了在细分标签中滑动-Ionic 3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码使用ionic 3中的片段.docs显示ngSwitch,ngModel的用法.但我只想在细分上滑动并切换到另一个细分标签.我怎样才能做到这一点?

The code below uses segments from ionic 3. docs show the use of ngSwitch, ngModel. but I would like to simply swipe on the segment and switch to another segment tab. How can I achieve this?

我不希望在顶部滑动标签,而是通过在内容上滑动来更改细分标签.

I am not interested in swiping the tabs at the top but by swiping on the content i would like to change the segment tab.

<ion-content padding>

  <div>
    <ion-segment [(ngModel)]="abc">
      <ion-segment-button value="Segment1">
        Segment Title
      </ion-segment-button>
      <ion-segment-button value="segment2">
        Segment Title
      </ion-segment-button>
    </ion-segment>
  </div>

  <div [ngSwitch]="abc">
    <ion-list *ngSwitchCase="'segment2'" class="list-fixed">
      <ion-item>
        <ion-thumbnail item-start>
          <img src="assets/imgs/1.jpg">
        </ion-thumbnail>
        <h2>List Item 1</h2>
        <p>List Item Subtitle</p>
        <button ion-button clear item-end>View</button>
      </ion-item>
    </ion-list>

    <ion-list *ngSwitchCase="'segment1'" class="list-fixed">
      <ion-item>
        <ion-thumbnail item-start>
          <img src="assets/imgs/3.png">
        </ion-thumbnail>
        <h2>List Item Title 1</h2>
        <p>Subheading</p>
        <button ion-button clear item-end>View</button>
      </ion-item>
    </ion-list>
  </div>

推荐答案

我的解决方法是添加:

//Add below code where you would like to detect the swipe from users input
// When user makes a swipe simply check and do the switch between Tabs.

(pan)='swipeEvent($event)' 

.ts文件

pages: string = "pageA";

swipeEvent($e) {
    console.log($e.deltaX+", "+$e.deltaY);
    if($e.deltaX > 0){
      console.log("Swipe from Left to Right");
      this.pages = "pageB";
    }else{
      console.log("Swipe from Right to Left");
      this.pages = "pageA";
    }
}

感谢大卫的评论

这篇关于在细分标签中滑动-Ionic 3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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