Gestures
在iOS设备上,一个Gesture事件在两个或更多手指触摸屏幕时被触发。如果任何手指落在你正监听Gesture事件(gesturestart,gesturechange,gestureend)的节点上,你将收到对应的Gesture事件。
Gesture事件提供一个GestureEvent对象,该对象包含以下属性:
* rotation: 使用手指旋转的角度。 * scale: 用户使用手指进行pinch和push操作时产生的一个倍数。如果大于1,用户则在进行push操作,小于1,则用户在进行pinch操作。
当同时监听了Gesture事件和Touch事件,则事件触发模式如下:
* touchstart 第一个手指接触屏幕时触发 * gesturestart 第二个手指接触屏幕时触发 * touchstart 第二个手指接触屏幕时触发 * gesturechange 两个手指都在屏幕上时,每次手指在屏幕上移动时触发 * gestureend 第二个手指 离开屏幕时触发 * touchend 第二个手指 离开屏幕时触发 * touchend 第一个手指 离开屏幕时触发
Resizing and rotating with the Gestures API
使用CSStransform,width,和height属性,我们可以很简单地使用这些Gesutre事件来缩放,旋转任何元素。
var width = 100,height = 200,rotation = 0;
node.addEventListener("gesturechange",function(event){
var style = event.target.style;
// scale and rotation are relative values,// so we wait to change our variables until the gesture ends
style.width = (width event.scale) + "px";
style.height = (height event.scale) + "px";
style.webkitTransform = "rotate(" + ((rotation
- event.rotation) % 360) + "deg)";
},false);
node.addEventListener("gestureend",function(event){
// Update the values for the next time a gesture happens
width = event.scale;
height = event.scale;
rotation = (rotation + event.rotation) % 360;
},false);
Dojo 1.7中更好的Gesture
Dojo 1.7包含了一个新的包dojox/gesture,它提供了处理触摸设备上更复杂的Gesture的能力。其中dojox/gesture/Base模块定义了一套可扩展出自定义Gesture的框架,除此之,该包还提供了一些常用Gesture的支持,如tap,tap and hold,double tap,and swipe。
使用dojox gesture非常简单。就像使用dojo/touch一样,为了监听某一个Gesture,你只需使用dojo.connect绑定一个Gesture,将传统的事件名替换为一个Gesture函数:
require([ "dojo","dojox/gesture/swipe","dojox/gesture/tap" ],function(dojo,swipe,tap){
dojo.connect(dojo.byId("myElement"),function(event){
// handle swipe event
});
dojo.connect(dojo.byId("myElement"),tap.doubletap,function(event){
// handle double tap event
});
});
将来,dojox/gesture将包含更多的Gesture种类,比如pinching和zooming。现在它提供了几种原本难以处理的事件的支持,以及一套跨平台可扩展的Gesture事件框架。 (编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|