From 3726ce7f95cbceffda24a73b7cbc713c2f2df8aa Mon Sep 17 00:00:00 2001 From: zilongshanren Date: Thu, 28 Jan 2016 13:52:05 +0800 Subject: [PATCH] fix node active in layout --- cocos2d/core/CCNode.js | 1 + cocos2d/core/components/CCLayout.js | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/cocos2d/core/CCNode.js b/cocos2d/core/CCNode.js index b1ecd2ac63..39a58e1dcd 100644 --- a/cocos2d/core/CCNode.js +++ b/cocos2d/core/CCNode.js @@ -261,6 +261,7 @@ var Node = cc.Class({ var canActiveInHierarchy = (this._parent && this._parent._activeInHierarchy); if (canActiveInHierarchy) { this._onActivatedInHierarchy(value); + this.emit('active-in-hierarchy-changed', this); } } } diff --git a/cocos2d/core/components/CCLayout.js b/cocos2d/core/components/CCLayout.js index 5b8439d3a6..ecf0d30258 100644 --- a/cocos2d/core/components/CCLayout.js +++ b/cocos2d/core/components/CCLayout.js @@ -285,6 +285,7 @@ var Layout = cc.Class({ this.node.on('anchor-changed', this._doLayoutDirty, this); this.node.on('child-added', this._childrenAddOrDeleted, this); this.node.on('child-removed', this._childrenAddOrDeleted, this); + this._updateChildrenEventListener(); }, @@ -298,6 +299,7 @@ var Layout = cc.Class({ child.on('size-changed', this._doLayoutDirty, this); child.on('position-changed', this._doLayoutDirty, this); child.on('anchor-changed', this._doLayoutDirty, this); + child.on('active-in-hierarchy-changed', this._doLayoutDirty, this); }.bind(this)); }, @@ -337,6 +339,9 @@ var Layout = cc.Class({ } children.forEach(function(child) { + if (!child.activeInHierarchy) { + return; + } //hacking for label child.getContentSize(); //for resizing children @@ -462,6 +467,10 @@ var Layout = cc.Class({ } children.forEach(function(child) { + if (!child.activeInHierarchy) { + return; + } + //hacking for label child.getContentSize(); //for resizing children