简体   繁体   English

iPhone web 应用程序 - 触摸和手势事件

[英]iPhone web app - touch and gesture events

looking at the (quite outdated) documentation on the apple website and across the internet for the touch and gesture javascript events, I can't help but notice that the gesture event which is returned during the function being called, only contains the values 'scale' and 'rotation'.查看苹果网站和互联网上有关触摸和手势 javascript 事件的(相当过时的)文档,我不禁注意到在调用 function 期间返回的手势事件,仅包含值 'scale '和'旋转'。 Have I missed something or are they the only two values returned?我错过了什么,还是它们是唯一返回的两个值?

It's hard to see the values of a returned object on the iPhone as they are annoyingly only shown as their type and name.很难在 iPhone 上看到返回的 object 的值,因为它们令人讨厌地只显示为它们的类型和名称。 eg when logging the returned object in the console, it just shows up as '[object TouchEvent]'.例如,在控制台中记录返回的 object 时,它只显示为“[object TouchEvent]”。

What I am trying to achieve is to run a function once a two finger swipe occurs, then whether the swipe was left or right, change the page accordingly.我想要实现的是在发生两指滑动时运行 function,然后无论滑动是向左还是向右,相应地更改页面。

I have tried a more complex touchevent and the (what I thought would be easier) gestureevent, but the gestureevent only returns the scale and rotation (apparently), and the touchevent seems quite complex in the way I am doing it.我尝试了更复杂的触摸事件和(我认为更容易的)手势事件,但是手势事件只返回缩放和旋转(显然),并且触摸事件在我这样做的方式上似乎相当复杂。

Does anyone know if the object returned is just the scale and rotation, and if so, do you know how I can get the same effect with the touchevent instead?有谁知道返回的 object 是否只是缩放和旋转,如果是这样,你知道我怎样才能用 touchevent 获得相同的效果吗?

You should use touchevent that provides you trajectory [of movements] to detect is this trajectory falls into "swipe" category using your own definition of swipe.您应该使用为您提供[运动]轨迹的 touchevent 来检测该轨迹是否属于使用您自己定义的滑动定义的“滑动”类别。

Usually "swipe" gesture is context specific: eg it should start in particular DOM element and probably end there.通常,“滑动”手势是特定于上下文的:例如,它应该从特定的 DOM 元素开始,并可能从那里结束。 It means that for particular DOM element some gesture is not a "swipe" but for its container for example it is a swipe.这意味着对于特定的 DOM 元素,某些手势不是“滑动”,但对于它的容器,例如它是滑动。 So you cannot generate bubbling event for that in general.因此,您通常无法为此生成冒泡事件。

Zoom and rotation gestures can be detected without knowing context - so system generates them for you.可以在不知道上下文的情况下检测缩放和旋转手势 - 因此系统会为您生成它们。

There are ready to use frameworks and libraries that have swipe gesture detectors.有现成的具有滑动手势检测器的框架和库。 At least for some popular containers like items in vertical list and so on.至少对于一些流行的容器,比如垂直列表中的项目等等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM