js 触摸事件
2014-02-19 16:36
281 查看
1.触摸事件 -- 单点
onTouchBegan:function(touch,event){
var touchPoint = touch.getLocation();
return true;//不会向下执行其他事件了
},
onTouchMoved:function (touch, event) {
},
onTouchEnded:function (touch, event) {
},
注册事件层
onEnter:function(){
cc.registerTargettedDelegate(cc.MENU_HANDLER_PRIORITY-1, true, this); //注册层次大于 0 不管用
this._super();
},
onExit:function(){
cc.unregisterTouchDelegate(this);
this._super();
}
2.触摸事件 -- 多点
onTouchesBegan:function (touches, event) {
},
onTouchesMoved:function (touches, event) {
if (touches) {
cc.p(touches[0].getLocation().x, touches[0].getLocation().y); //获得触摸地点坐标
var delta = touches[0].getDelta(); //delta.y 触摸动距离,根据这个可以移动控件
}
},
onTouchesEnded:function (touches, event) {},
onTouchesCancelled:function (touches, event) {}
3.屏蔽层
1.简单的屏蔽
(1)按钮实现:在一个 layer 上放一个和屏幕一样大的按钮 menu,设成透明的,所有低于这个按钮的事件都会被这个按钮所接受,不会向下传递。
(2)屏蔽层实现:
onEnter:function(){
cc.registerTargettedDelegate(cc.MENU_HANDLER_PRIORITY-1, true, this); //设成比按钮的层次低
this._super();
},
onExit:function(){
cc.unregisterTouchDelegate(this);
this._super();
}
onTouchBegan:function(touch,event){
var pos = this.Menu.convertTouchToNodeSpace(touch);//按钮的 Menu
var ret = true;
if(cc.rectContainsPoint(this.ItemMenu.rect(), pos1))//按钮的ItemMenu
{
this._close.activate();//可无
ret = false;
}
return ret;//返回 true 屏蔽所有
},
2.屏蔽层上又 tableview、scrollview 。。。
按钮实现:这些 UI 事件都低于按钮事件,很多事件都会在设的按钮屏蔽层处理掉,tableview 。。。事件不会响应。
table.setTouchPriority(cc.MENU_HANDLER_PRIORITY-2); //设成比按钮处理事件层高就行了。
3.scrollview上有tableview,滑动tableview时scrollview不动
(1)tableview 所在的 layer
this.setTouchPriority(cc.MENU_HANDLER_PRIORITY-2);
this.setTouchMode(cc.TOUCH_ONE_BY_ONE);
this.setTouchEnabled(true);
tableView.setTouchPriority(cc.MENU_HANDLER_PRIORITY-3);
onTouchBegan:function (touch, event) {
var pos = touch.getLocation();
if(cc.rectContainsPoint(rect, pos)){//触摸在tableview 上不向下传递则scrollview 无法响应
return true;
}
return false;
},
4.通过移除和添加屏蔽层,实现一些屏蔽
4.按钮屏蔽问题
按钮做底层屏蔽一些事件,会影响到有限级别低于按钮的事件,大部分事件都在按钮层处理了。
1.单触摸事件
this.setTouchPriority(cc.MENU_HANDLER_PRIORITY-2); //层设的比按钮低
this.setTouchEnabled(true);
this.setTouchMode(cc.TOUCH_ONE_BY_ONE);
onTouchBegan:function (touch, event) { //必须返回 true onTouchMoved才能接到事件
return true;
},
onTouchMoved 才会响应
层上的其他按钮好使
设置按钮 menu.setTouchPriority(cc.MENU_HANDLER_PRIORITY-3);
方法
this.setTouchPriority(cc.MENU_HANDLER_PRIORITY-2);
this.setTouchMode(cc.TOUCH_ONE_BY_ONE);
this.setTouchEnabled(true);
onTouchBegan:function(touch,event){
var touchPoint = touch.getLocation();
return true;//不会向下执行其他事件了
},
onTouchMoved:function (touch, event) {
},
onTouchEnded:function (touch, event) {
},
注册事件层
onEnter:function(){
cc.registerTargettedDelegate(cc.MENU_HANDLER_PRIORITY-1, true, this); //注册层次大于 0 不管用
this._super();
},
onExit:function(){
cc.unregisterTouchDelegate(this);
this._super();
}
2.触摸事件 -- 多点
onTouchesBegan:function (touches, event) {
},
onTouchesMoved:function (touches, event) {
if (touches) {
cc.p(touches[0].getLocation().x, touches[0].getLocation().y); //获得触摸地点坐标
var delta = touches[0].getDelta(); //delta.y 触摸动距离,根据这个可以移动控件
}
},
onTouchesEnded:function (touches, event) {},
onTouchesCancelled:function (touches, event) {}
3.屏蔽层
1.简单的屏蔽
(1)按钮实现:在一个 layer 上放一个和屏幕一样大的按钮 menu,设成透明的,所有低于这个按钮的事件都会被这个按钮所接受,不会向下传递。
(2)屏蔽层实现:
onEnter:function(){
cc.registerTargettedDelegate(cc.MENU_HANDLER_PRIORITY-1, true, this); //设成比按钮的层次低
this._super();
},
onExit:function(){
cc.unregisterTouchDelegate(this);
this._super();
}
onTouchBegan:function(touch,event){
var pos = this.Menu.convertTouchToNodeSpace(touch);//按钮的 Menu
var ret = true;
if(cc.rectContainsPoint(this.ItemMenu.rect(), pos1))//按钮的ItemMenu
{
this._close.activate();//可无
ret = false;
}
return ret;//返回 true 屏蔽所有
},
2.屏蔽层上又 tableview、scrollview 。。。
按钮实现:这些 UI 事件都低于按钮事件,很多事件都会在设的按钮屏蔽层处理掉,tableview 。。。事件不会响应。
table.setTouchPriority(cc.MENU_HANDLER_PRIORITY-2); //设成比按钮处理事件层高就行了。
3.scrollview上有tableview,滑动tableview时scrollview不动
(1)tableview 所在的 layer
this.setTouchPriority(cc.MENU_HANDLER_PRIORITY-2);
this.setTouchMode(cc.TOUCH_ONE_BY_ONE);
this.setTouchEnabled(true);
tableView.setTouchPriority(cc.MENU_HANDLER_PRIORITY-3);
onTouchBegan:function (touch, event) {
var pos = touch.getLocation();
if(cc.rectContainsPoint(rect, pos)){//触摸在tableview 上不向下传递则scrollview 无法响应
return true;
}
return false;
},
4.通过移除和添加屏蔽层,实现一些屏蔽
4.按钮屏蔽问题
按钮做底层屏蔽一些事件,会影响到有限级别低于按钮的事件,大部分事件都在按钮层处理了。
1.单触摸事件
this.setTouchPriority(cc.MENU_HANDLER_PRIORITY-2); //层设的比按钮低
this.setTouchEnabled(true);
this.setTouchMode(cc.TOUCH_ONE_BY_ONE);
onTouchBegan:function (touch, event) { //必须返回 true onTouchMoved才能接到事件
return true;
},
onTouchMoved 才会响应
层上的其他按钮好使
设置按钮 menu.setTouchPriority(cc.MENU_HANDLER_PRIORITY-3);
方法
this.setTouchPriority(cc.MENU_HANDLER_PRIORITY-2);
this.setTouchMode(cc.TOUCH_ONE_BY_ONE);
this.setTouchEnabled(true);
相关文章推荐
- js 触摸事件
- quojs 及 转:11个处理触摸事件和多点触摸的JS库
- 移动端js触摸事件详解
- cocos2d JS touch(触摸监听)-快速添加事件监听器到管理器
- coco2d-js 触摸移动的同时处理点击事件
- JS移动设备触摸事件API
- 11 个处理触摸事件和多点触摸的 JS 库
- [js点滴]触摸事件与手势事件
- JS触摸事件、手势事件详解
- 关于js-binding中Layer触摸事件的优化
- vue.js添加一些触摸事件以及安装fastclick的实例
- cocos-js触摸事件
- vue.js添加一些触摸事件以及安装fastclick
- 11 个处理触摸事件和多点触摸的 JS 库
- JS触摸与手势事件详解
- JS事件监听手机屏幕触摸事件 Touch
- 移动端js触摸事件
- 11 个处理触摸事件和多点触摸的 JS 库
- 移动web开发,12个触摸及多点触摸事件常用Js插件
- cocos2d - JS 单点触摸事件和鼠标事件