【问题标题】:How to use gestures with Ionic 3?如何在 Ionic 3 中使用手势?
【发布时间】:2019-10-09 20:31:49
【问题描述】:

我在 Ionic 3(Angular 和 Typescript)中使用平移和滑动手势来触发操作。现在我是这样使用它的:

*.html :

<button ion-button block (panleft)="actionForLeftPan()"  (panright)="actionForRightPan()">Touch me</button>

*.ts:

actionForLeftPan(): void
{
    // Some actions
}

actionForRightPan(): void
{
    // Some other actions
}

它可以工作,但在某些情况下,它需要在 html 文件中调用很多函数。有没有办法做一些事情,例如这样的事情:

*.html:

<button ion-button block (pan)="actionForPan(event)">Touch me</button>

*.ts:

actionForPan(event): void
{
    if ( event.left )
    {
        // Do some actions
    }

    if ( event.right )
    {
        // Do other actions
    }
}

这将大大简化代码的可读性和维护。

【问题讨论】:

  • 你所要做的就是在调用 (pan)="actionForPan($event)" 时传入 $event。您应该在 actionForPan() 中使用 console.log(event) 来查看结果。
  • 谢谢JoeriShoeby,这正是我所需要的。

标签: angular ionic-framework ionic3


【解决方案1】:

你要做的就是在调用 (pan)="actionForPan($event)" 时传入 $event。您应该在 actionForPan() 中使用 console.log(event) 来查看结果。

更多信息请访问:GestureController Source Code

【讨论】:

    猜你喜欢
    • 2021-03-28
    • 2018-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-28
    • 1970-01-01
    相关资源
    最近更新 更多