【问题标题】:Detect multiple touches in Ionic/Android WebView在 Ionic/Android WebView 中检测多个触摸
【发布时间】:2014-10-02 14:52:44
【问题描述】:

在 ionic 应用程序中,我正在观看 on-swipe-right 指令以实现“返回”功能。

doctype html5
html(lang='en', ng-app='my-app')
  head
    meta(charset='utf-8')
    meta(http-equiv='X-UA-Compatible', content='IE=edge,chrome=1')
    meta(name='viewport', content='width=device-width,initial-scale=1')

//- snip

  body(
    ng-controller="DoloresMainCtrl"
    on-swipe-right="toMainScreen($event)"
  )
    ion-nav-view

在控制器中

angular.module('my-app', [
    'ui.router'
])
.controller 'DoloresMainCtrl', ($scope, $state)->
    $scope.toMainScreen = ($event)->
        $state.go '^' if $event?.gesture?.touches?.length is 2

事件触发得很好,但$event.gesture.touches.length 始终是1

我需要设置什么来让 ionic 检测多个触摸?

(约束:Android 4.4+、iOS 8+)

【问题讨论】:

  • 我也对这个问题的答案感兴趣。 Ionic 使用了一个hammer.js 的fork 来处理触摸事件,而在hammer.js 中可以检测到多个触摸,那么为什么不在Ionic 中呢?

标签: android ios angularjs touch ionic-framework


【解决方案1】:

这是一个可以为点击事件检测多个触摸点的工作示例。点的触摸开始必须非常同时才能算作多次点击。否则,它们将被视为两次连续点击。

angular.module('my-app', ['ui.router'])
    .directive('multiTap', function () {
        return {
            restrict: 'A',
            link: function postLink(scope, element, attrs) {
                element.text('this is the multi-tap directive');
                var tap = ionic.onGesture("tap", handler, element[0]);
                function handler(e) { console.log(e);
                    element.text(e.type + e.gesture.touches.length);
                }
            }
        };
    });

HTML 示例:

<ion-content class="padding" multi-tap>

【讨论】:

  • 没有忽略你的回答,只是忙于其他事情!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-02-28
  • 2012-04-18
  • 1970-01-01
  • 1970-01-01
  • 2022-10-02
相关资源
最近更新 更多