检测夹点的最简单方法 [英] Simplest way to detect a pinch

查看:144
本文介绍了检测夹点的最简单方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是 WEB APP ,而不是原生应用。请不要使用Objective-C NS命令。

This is a WEB APP not a native app. Please no Objective-C NS commands.

所以我需要在iOS上检测'pinch'事件。问题是我看到的用于做手势或多点触摸事件的每个插件或方法,(通常)使用jQuery,并且是针对阳光下每个手势的完整附加插件。我的应用程序非常庞大,我对代码中的枯木非常敏感。我只需要检测一个捏,使用像jGesture这样的东西就可以满足我的简单需求。

So I need to detect 'pinch' events on iOS. Problem is every plugin or method I see for doing gestures or multi-touch events, is (usually) with jQuery and is a whole additional pluggin for every gesture under the sun. My application is huge, and I am very sensitive to deadwood in my code. All I need is to detect a pinch, and using something like jGesture is just way to bloated for my simple needs.

此外,我对如何检测的理解有限手动捏。我可以得到两个手指的位置,似乎无法正确地检测到这一点。有没有人有一个只能检测到夹点的简单片段?

Additionally, I have a limited understanding of how to detect a pinch manually. I can get the position of both fingers, can't seem to get the mix right to detect this. Does anyone have a simple snippet that JUST detects pinch?

推荐答案

你想使用 gesturestart gesturechange ,和 gestureend 活动。每当有两个或多个手指触摸屏幕时,这些都会被触发。

You want to use the gesturestart, gesturechange, and gestureend events. These get triggered any time 2 or more fingers touch the screen.

根据您需要对捏合手势进行操作,您的方法需要进行调整。可以检查比例乘数,以确定用户捏合手势的戏剧性。有关规模 Apple的TouchEvent文档。 c $ c>属性将表现。

Depending on what you need to do with the pinch gesture, your approach will need to be adjusted. The scale multiplier can be examined to determine how dramatic the user's pinch gesture was. See Apple's TouchEvent documentation for details about how the scale property will behave.

node.addEventListener('gestureend', function(e) {
    if (e.scale < 1.0) {
        // User moved fingers closer together
    } else if (e.scale > 1.0) {
        // User moved fingers further apart
    }
}, false);

您还可以拦截 gesturechange 事件如果你需要它来使你的应用程序感觉更敏感,就会检测到捏合。

You could also intercept the gesturechange event to detect a pinch as it happens if you need it to make your app feel more responsive.

这篇关于检测夹点的最简单方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆