Ionic 2 làm cho sử dụng thư viện hammerjs để xử lý những cử chỉ của nó.
Họ cũng đã xây dựng lớp Gesture của riêng họ hoạt động hiệu quả như một trình bao bọc cho hammerjs: Gesture.ts.
Vì vậy, bạn có thể thực hiện chỉ thị riêng của bạn như:
import {Directive, ElementRef, Input, OnInit, OnDestroy} from 'angular2/core'
import {Gesture} from 'ionic-angular/gestures/gesture'
declare var Hammer: any
/*
Class for the SwipeVertical directive (attribute (swipe) is only horizontal).
In order to use it you must add swipe-vertical attribute to the component.
The directives for binding functions are [swipeUp] and [swipeDown].
IMPORTANT:
[swipeUp] and [swipeDown] MUST be added in a component which
already has "swipe-vertical".
*/
@Directive({
selector: '[swipe-vertical]' // Attribute selector
})
export class SwipeVertical implements OnInit, OnDestroy {
@Input('swipeUp') actionUp: any;
@Input('swipeDown') actionDown: any;
private el: HTMLElement
private swipeGesture: Gesture
private swipeDownGesture: Gesture
constructor(el: ElementRef) {
this.el = el.nativeElement
}
ngOnInit() {
this.swipeGesture = new Gesture(this.el, {
recognizers: [
[Hammer.Swipe, {direction: Hammer.DIRECTION_VERTICAL}]
]
});
this.swipeGesture.listen()
this.swipeGesture.on('swipeup', e => {
this.actionUp()
})
this.swipeGesture.on('swipedown', e => {
this.actionDown()
})
}
ngOnDestroy() {
this.swipeGesture.destroy()
}
}
Mã này cho phép bạn làm điều gì đó như thế này:
<div swipe-vertical [swipeUp]="mySwipeUpAction()" [swipeDown]="mySwipeDownAction()">
Nguồn
2017-06-09 12:48:58
Bạn có tìm ra cách để làm điều đó? – brians69
@ drbishop thật không may, tôi chỉ thực hiện nó từ mặt đất lên bản thân mình: ( –
Bạn vẫn cần một soulution? – Duannx