From 2ef2e3d35d89161ff82e68f16f3d2d59263f4e18 Mon Sep 17 00:00:00 2001 From: knoxHuang <821686174@qq.com> Date: Thu, 22 Sep 2016 11:06:35 +0800 Subject: [PATCH] Perfect operation for CCSlider --- cocos2d/core/components/CCSlider.js | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/cocos2d/core/components/CCSlider.js b/cocos2d/core/components/CCSlider.js index 6c57b46cd1..d0ab2d5929 100644 --- a/cocos2d/core/components/CCSlider.js +++ b/cocos2d/core/components/CCSlider.js @@ -127,12 +127,24 @@ var Slider = cc.Class({ this._updateHandlePosition(); }, + onDestroy: function() { + this.node.off(cc.Node.EventType.TOUCH_START, this._onTouchBegan, this); + this.node.off(cc.Node.EventType.TOUCH_MOVE, this._onTouchMoved, this); + this.node.off(cc.Node.EventType.TOUCH_END, this._onTouchEnded, this); + this.node.off(cc.Node.EventType.TOUCH_CANCEL, this._onTouchCancelled, this); + if (this.handle) { + this.handle.node.off(cc.Node.EventType.TOUCH_START, this._onHandleDragStart, this); + this.handle.node.off(cc.Node.EventType.TOUCH_MOVE, this._onTouchMoved, this); + this.handle.node.off(cc.Node.EventType.TOUCH_END, this._onTouchEnded, this); + } + }, + // 注册事件 _registerEvent: function () { - this.node.on(cc.Node.EventType.TOUCH_START, this._onTouchBegan, this, true); - this.node.on(cc.Node.EventType.TOUCH_MOVE, this._onTouchMoved, this, true); - this.node.on(cc.Node.EventType.TOUCH_END, this._onTouchEnded, this, true); - this.node.on(cc.Node.EventType.TOUCH_CANCEL, this._onTouchCancelled, this, true); + this.node.on(cc.Node.EventType.TOUCH_START, this._onTouchBegan, this); + this.node.on(cc.Node.EventType.TOUCH_MOVE, this._onTouchMoved, this); + this.node.on(cc.Node.EventType.TOUCH_END, this._onTouchEnded, this); + this.node.on(cc.Node.EventType.TOUCH_CANCEL, this._onTouchCancelled, this); if (this.handle) { this.handle.node.on(cc.Node.EventType.TOUCH_START, this._onHandleDragStart, this); this.handle.node.on(cc.Node.EventType.TOUCH_MOVE, this._onTouchMoved, this); @@ -140,7 +152,7 @@ var Slider = cc.Class({ } }, - _onHandleDragStart: function () { + _onHandleDragStart: function (event) { this._dragging = true; event.stopPropagation(); },