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