Swipe up/down not working on Ionic 2

a 夏天 提交于 2019-12-13 12:32:27

问题


How can I use swipe up or swipe down with Ionic 2?

I've tried the Gestures API but it only fires on horizontal swipe.

<ion-card (swipe)="swipePage($event)">
</ion-card>

回答1:


In the HammerJS official document, bottom line says :

When calling Hammer() to create a simple instance, the pan and swipe recognizers are configured to only detect horizontal gestures.

For additional config, you must tweak your hammer instance, try this :

First run npm install hammerjs --save && npm install @types/hammerjs --save-dev

import { HammerGestureConfig, HAMMER_GESTURE_CONFIG } from '@angular/platform-browser';
import * as Hammer from 'hammerjs';

// create a class that overrides hammer default config

export class MyHammerConfig extends HammerGestureConfig  {
  overrides = <any>{
    'swipe': { direction: Hammer.DIRECTION_ALL } // override default settings
  }
}

// In your module providers, add this :

providers: [{ 
  provide: HAMMER_GESTURE_CONFIG, 
  useClass: MyHammerConfig 
}]


来源:https://stackoverflow.com/questions/42196219/swipe-up-down-not-working-on-ionic-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!