cocostudio 事件穿透(coco2dx 3.2)
来源:互联网 发布:wpsh5是什么软件 编辑:程序博客网 时间:2024/05/01 19:34
因为经常需要让事件穿透到下一层的scrollview.可在cocostudio 中默认并没有开启事件穿透.查看原代码看到直接setSwallowTouches为true了.
对UIWidget做出如下的处理
在UIWidget.h中加入三个成员变量用与控制事件穿透
//UIWidget.h中的改动
public:/** * Sets whether the widget swallow touches * the default value is true * @param needSwallow true if the widget is need to swallow touches * @param always false if the widget will swallow touches only when hitTest success */void setSwallowTouches(bool needSwallow,bool always = true);private:bool _swallowTouches;//控制是否需要穿透bool _penetrateTouchesAlways;//用于决定是否总是穿透.bool _hadMoveOutHitArea;//用于判断是否在移动过程中移出点击区域
//UIWidget.cpp中的改动
void Widget::setSwallowTouches(bool needSwallow,bool always/* = true*/){if (_touchListener){_touchListener->setSwallowTouches(needSwallow);}_swallowTouches = needSwallow;_penetrateTouchesAlways = always;}bool Widget::onTouchBegan(Touch *touch, Event *unusedEvent){ _hitted = false; if (isVisible() && isEnabled() && isAncestorsEnabled() && isAncestorsVisible(this) ) { _touchBeganPosition = touch->getLocation(); if(hitTest(_touchBeganPosition) && isClippingParentContainsPoint(_touchBeganPosition)) { _hitted = true; } } if (!_hitted) { return false; } setHighlighted(true); Widget* widgetParent = getWidgetParent(); if (widgetParent) { widgetParent->interceptTouchEvent(TouchEventType::BEGAN, this, touch); } pushDownEvent();// if (!_penetrateTouchesAlways)// {// _touchListener->setSwallowTouches(true);// log("beginning~~~~~~~~~~~~~~~~~~~~~~~~~~~~");// }_hadMoveOutHitArea = false; return true;}void Widget::onTouchMoved(Touch *touch, Event *unusedEvent){ _touchMovePosition = touch->getLocation();if (hitTest(_touchMovePosition)){setHighlighted(true);if (!_swallowTouches && !_penetrateTouchesAlways && !_hadMoveOutHitArea)_touchListener->setSwallowTouches(true);}else{setHighlighted(false);if (!_swallowTouches && !_penetrateTouchesAlways){_touchListener->setSwallowTouches(false);_hadMoveOutHitArea = true;}} Widget* widgetParent = getWidgetParent(); if (widgetParent) { widgetParent->interceptTouchEvent(TouchEventType::MOVED, this, touch); } moveEvent();}void Widget::onTouchEnded(Touch *touch, Event *unusedEvent){ bool highlight = _highlight; setHighlighted(false); if (!_swallowTouches && !_penetrateTouchesAlways){_touchListener->setSwallowTouches(false);if (_hadMoveOutHitArea)return;} _touchEndPosition = touch->getLocation(); Widget* widgetParent = getWidgetParent(); if (widgetParent) { widgetParent->interceptTouchEvent(TouchEventType::ENDED, this, touch); } if (highlight) { releaseUpEvent(); } else { cancelUpEvent(); }}
0 0
- cocostudio 事件穿透(coco2dx 3.2)
- cocostudio中UI动画的程序调用coco2dx v3.2
- coco2dx 3.0 EventDispatcher事件派发
- 事件穿透
- 穿透事件
- coco2dx-3.2 shader效果
- Cocostudio touch事件传递机制
- Cocostudio按钮事件不能响应
- cocoStudio: button触摸事件响应
- 1、coco2dx环境搭配+xcode5 + coco2dx 3.2alpha0
- div 嵌套 事件穿透
- uiview点击事件穿透
- View事件穿透,解决方法
- android点击事件穿透
- ios 事件穿透
- DrawerLayout 点击事件穿透
- DrawerLayout 点击穿透事件
- 点击按钮事件穿透
- js 继承实现
- js 中null 和undefined的区别
- 编程学习笔记2--枚举的应用
- 单例模式再讨论(有关序列化的单例问题)
- solr第一弹 autocomplete(自动补全)
- cocostudio 事件穿透(coco2dx 3.2)
- lucene多索引上的搜索
- jquery 分页插件
- mssql 追加行号 row_number()的用法
- 如何查看js生成的html
- ecplise下配置c++运行环境
- 合并字符串中所有的子字符串
- hash算法 (hashmap 实现原理)
- solr/home是个什么东西