BUG?Layout节点隐藏后再显示,不会刷新子节点位置

1.6 beta3

demo中4个节点竖着排列,ResizeMode: Container
改变layout节点active = false,然后设置其中一个子节点显示,其他隐藏,
再设置layout节点active=true,显示的子节点不会竖直居中。

代码很简单,先隐藏,后重置有问题,不隐藏没问题:

const {ccclass, property} = cc._decorator;

@ccclass
export default class NewClass extends cc.Component {
@property(cc.Node)
theNode: cc.Node;

private node1: cc.Node;
private node2: cc.Node;
private node3: cc.Node;
private node4: cc.Node;
public onLoad() {
    this.node1 = this.theNode.getChildByName('node1');
    this.node2 = this.theNode.getChildByName('node2');
    this.node3 = this.theNode.getChildByName('node3');
    this.node4 = this.theNode.getChildByName('node4');
    this.node1.active = false;
    this.node2.active = false;
    this.node3.active = true;
    this.node4.active = false;
}
/**
 * 先隐藏,后重置
 */
public resetNode() {
    this.theNode.active = false;
    this.doReset();
    this.theNode.active = true;
}
/**
 * 不隐藏重置
 */
public resetNode1() {
    this.doReset();
}
private doReset() {
    this.theNode.setPosition(200, 0);
    this.node1.active = true;
    this.node2.active = false;
    this.node3.active = false;
    this.node4.active = false;
}

}

NewProject.rar (422.4 KB)

没人遇到过吗?

应该是按节点居中的,除非你把节点删掉

是应该按layout节点居中,然而demo中并没有,所以是问题呀。。。

别沉。。。。。。。

隐藏后 节点的位置更新有问题,可以调用隐藏方法手动更新 node.getComponent(cc.Layout)._updateLayout()

这个接口是内部的呀,而且我不需要当前帧进行操作,所以也没必要刷新吧,只需下一帧正常显示出来就好啊。

1赞

@Knox 出来接锅啦!

呼叫失败啊,再召唤一下。

我测试一下, 算是 bug,已经修复了,如果着急的话,用下面这个 PR 自己定制

https://github.com/cocos-creator/engine/pull/1892

貌似我也遇到这个问题,。1.5.2里,一个node.active=false后,再node.active=true 这个node里的子节点,有的位置也会不正确

我提的这个官方找到的问题是CCLayout组件忘记反注册一大堆系统事件了,因为需要自己合并PR,所以我还没验证是不是这个原因呢。

你的这个节点的子节点包含哪些组件?

1.6里还有这个问题。我一个场景里有一个sprite居然显示,然后把这个场景active=false,再回来的时候 ,发现这个sprint不是居中了,跑到最左边了,但是看他的position还是中间

我也遇到了…

能不能给一个 demo,这样比较好重现,感谢(PS: 为毛你们都很喜欢歪楼…)