【问题标题】:Swipe through segment tabs - Ionic 3扫过段标签 - Ionic 3
【发布时间】:2017-10-27 11:10:26
【问题描述】:

下面的代码使用了 ionic 3 中的片段。文档显示了 ngSwitch、ngModel 的使用。但我想简单地在细分上滑动并切换到另一个细分选项卡。我怎样才能做到这一点?

我对滑动顶部的选项卡不感兴趣,但通过滑动内容我想更改分段选项卡。

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

【问题讨论】:

  • 离子的片段不支持这个。你必须自己实现它。提示:Angular/Ionic 带有 HammerJS,因此您可以使用 panleftpanright 事件来检测滑动手势。

标签: angular ionic-framework ionic3


【解决方案1】:

我的解决方案是添加:

.html 文件

//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";
    }
}

感谢大卫的评论

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-07-07
    • 2018-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-16
    相关资源
    最近更新 更多