[0]某个独立的textInput输入时,调用box.destroyChildren时 导致这个不造box内的独立textInput组件失焦切无法继续输入
在官方的 2D-UI-input组件demo库中写了如下的代码 即可复现此问题
let
SPACING = 100,
INPUT_WIDTH = 300,
INPUT_HEIGHT = 50,
Y_OFFSET = 50,
skins,
box = null;
class UI_Input {
constructor() {
const
Browser = Laya.Browser,
WebGL = Laya.WebGL,
Stage = Laya.Stage,
Stat = Laya.Stat,
Handler = Laya.Handler;
// 不支持WebGL时自动切换至Canvas
Laya.init(800, 600, WebGL);
Laya.stage.alignV = Stage.ALIGN_MIDDLE;
Laya.stage.alignH = Stage.ALIGN_CENTER;
Laya.stage.scaleMode = Stage.SCALE_SHOWALL;
Laya.stage.bgColor = "#232628";
Stat.show();
skins = ["res/ui/input (1).png", "res/ui/input (2).png", "res/ui/input (3).png", "res/ui/input (4).png"]
Laya.loader.load(skins, Handler.create(this, this.onLoadComplete));
box = new Laya.Box();
Laya.stage.addChild(box);
}
onLoadComplete() {
for (let i = 0, len = skins.length; i < len; ++i) {
var input = this.createInput(skins[i]);
box.addChild(input);
input.prompt = 'Type:';
input.x = (Laya.stage.width - input.width) / 2;
input.y = i * SPACING + Y_OFFSET;
}
this.createInput();
}
createInput(skin) {
const TextInput = Laya.TextInput;
var ti = new TextInput();
if(skin){
ti.skin = skin;
ti.size(300, 50);
ti.sizeGrid = "0,40,0,40";
ti.font = "Arial";
ti.fontSize = 30;
ti.bold = true;
ti.color = "#606368";
}else{
ti.size(300, 50);
ti.skin = "res/ui/input (1).png";
ti.sizeGrid = "0,40,0,40";
ti.font = "Arial";
ti.fontSize = 30;
ti.bold = true;
ti.color = "#606368";
ti.on(Laya.Event.CHANGE, null, () => {
// this.destroyAll();
console.log('22222');
})
ti.on(Laya.Event.INPUT, null, () => {
console.log('111111');
this.destroyAllInput();
})
Laya.stage.addChild(ti);
}
return ti;
}
destroyAllInput(){
box.destroyChildren();
}
}
new UI_Input();
let
SPACING = 100,
INPUT_WIDTH = 300,
INPUT_HEIGHT = 50,
Y_OFFSET = 50,
skins,
box = null;
class UI_Input {
constructor() {
const
Browser = Laya.Browser,
WebGL = Laya.WebGL,
Stage = Laya.Stage,
Stat = Laya.Stat,
Handler = Laya.Handler;
// 不支持WebGL时自动切换至Canvas
Laya.init(800, 600, WebGL);
Laya.stage.alignV = Stage.ALIGN_MIDDLE;
Laya.stage.alignH = Stage.ALIGN_CENTER;
Laya.stage.scaleMode = Stage.SCALE_SHOWALL;
Laya.stage.bgColor = "#232628";
Stat.show();
skins = ["res/ui/input (1).png", "res/ui/input (2).png", "res/ui/input (3).png", "res/ui/input (4).png"]
Laya.loader.load(skins, Handler.create(this, this.onLoadComplete));
box = new Laya.Box();
Laya.stage.addChild(box);
}
onLoadComplete() {
for (let i = 0, len = skins.length; i < len; ++i) {
var input = this.createInput(skins[i]);
box.addChild(input);
input.prompt = 'Type:';
input.x = (Laya.stage.width - input.width) / 2;
input.y = i * SPACING + Y_OFFSET;
}
this.createInput();
}
createInput(skin) {
const TextInput = Laya.TextInput;
var ti = new TextInput();
if(skin){
ti.skin = skin;
ti.size(300, 50);
ti.sizeGrid = "0,40,0,40";
ti.font = "Arial";
ti.fontSize = 30;
ti.bold = true;
ti.color = "#606368";
}else{
ti.size(300, 50);
ti.skin = "res/ui/input (1).png";
ti.sizeGrid = "0,40,0,40";
ti.font = "Arial";
ti.fontSize = 30;
ti.bold = true;
ti.color = "#606368";
ti.on(Laya.Event.CHANGE, null, () => {
// this.destroyAll();
console.log('22222');
})
ti.on(Laya.Event.INPUT, null, () => {
console.log('111111');
this.destroyAllInput();
})
Laya.stage.addChild(ti);
}
return ti;
}
destroyAllInput(){
box.destroyChildren();
}
}
new UI_Input();
没有找到相关结果
已邀请:
要回复问题请先登录
1 个回复
小高
赞同来自: