我们在手机中常常用到长按、滑动、点击旋转、以及敲击等各种事件,如何具体使用呢?请看下文:

tap  点击事件、      press 长按事件 、   pan 滑动多次触发、    swipe 滑动一次触发、   rotate 旋转事件、   pinch 捏合手势

第一步,在vscode终端安装hammerjs

npm install hammerjs --save

第二步,在主目录,即src/main.ts中引入hammerjs

ionic4中手势事件的使用

第三步,例如我们写一个长按手势的事件

ionic4中手势事件的使用

 async doPress(){
    const alert = await this.alertController.create({

      backdropDismiss:false,
      header: '提示',
      message: '确定要删除吗!',
      buttons: [
        {
          text: '取消',
          role: 'cancel',
          cssClass: 'secondary',
          handler: (blah) => {
            console.log('Confirm Cancel: blah');
          }
        }, {
          text: '确定',
          handler: () => {
            console.log('Confirm Okay');
          }
        }
      ]
    });
    await alert.present();

  }

效果展示:

ionic4中手势事件的使用

手势事件很常用,步骤不要丢哦!

相关文章:

  • 2021-12-10
  • 2021-06-02
  • 2022-12-23
  • 2021-12-24
  • 2022-12-23
  • 2021-08-27
  • 2022-12-23
猜你喜欢
  • 2021-07-08
  • 2021-06-07
  • 2021-11-18
  • 2021-10-30
  • 2022-12-23
相关资源
相似解决方案