Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 爱奥尼亚2中的垂直滑动/拖动手势_Javascript_Ionic Framework_Ionic2 - Fatal编程技术网

Javascript 爱奥尼亚2中的垂直滑动/拖动手势

Javascript 爱奥尼亚2中的垂直滑动/拖动手势,javascript,ionic-framework,ionic2,Javascript,Ionic Framework,Ionic2,我需要在Ionic 2应用程序中使用swipeup/swipedown手势。当我这样做的时候 <div (swipe)='someFunction($event)'></div> 然后调用我的someFunction(e),但只在水平幻灯片上调用,因此我无法听到上下方向的滑动(swipeup)和(swipedown)似乎什么都不做。你知道这在爱奥尼亚beta版上是否可行吗?只是一个更新,爱奥尼亚现在有了手势控制。看 手势返回一个$event对象。您可能可以使用此数

我需要在Ionic 2应用程序中使用swipeup/swipedown手势。当我这样做的时候

<div (swipe)='someFunction($event)'></div>


然后调用我的
someFunction(e)
,但只在水平幻灯片上调用,因此我无法听到上下方向的滑动
(swipeup)
(swipedown)
似乎什么都不做。你知道这在爱奥尼亚beta版上是否可行吗?

只是一个更新,爱奥尼亚现在有了手势控制。看

手势返回一个
$event
对象。您可能可以使用此数据检查它是否为swipeup/swipedown事件


爱奥尼亚2利用hammerjs库处理手势

他们还构建了自己的手势类,有效地充当hammerjs:signate.ts的包装器

因此,您可以执行自己的指令,如:

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()
  }
}
此代码允许您执行以下操作:

<div swipe-vertical [swipeUp]="mySwipeUpAction()" [swipeDown]="mySwipeDownAction()">


你知道怎么做了吗?@drbishop不幸的是,我自己刚刚从头开始实施了它:(你还需要解决方案吗?@duanx正如我所说,已经从头开始实施了:(