libgdx:IOS 屏幕键盘未持续触发事件

libgdx: IOS on screen keyboard not firing events consistently

我仅在 IOS 构建时遇到 InputProcessor 问题。此代码适用于桌面和 Android 构建但不适用于 iOS.

基本上,只要用户在屏幕键盘上键入内容,我就需要捕获一个事件。但是在 iOS 中,我只能间歇性地看到 keyTyped 的 println,并且只有当我在屏幕键盘上快速键入时才会看到。所有其他触摸只是在控制台中显示一个新行,我不确定这个新行输出来自哪里。

问题似乎源于 iOS 将事件发送回我的应用程序以及 LibGDX InputProcessor 如何接收它们。我尝试创建自己的对象,它扩展了 TextField 并实现了 InputProcessor,然后将该对象的实例设置为 inputProcessor,但我得到了相同的结果。如果我触摸屏幕上除 iOS 屏幕键盘之外的任何地方,我会持续触发事件。

这是 iOS 当我打字速度非常快时控制台输出的样子,如果我打字速度慢,则 println 永远不会显示:

game name field key typed!


game name field key typed!






game name field key typed!

在 android 设备 (nexus 7) 上做同样的事情会产生以下结果(这是我所期望的):

I/System.out: game name field key down!
I/System.out: game name field key up!
I/System.out: game name field key typed!
I/System.out: game name field key down!
I/System.out: game name field key up!
I/System.out: game name field key typed!
I/System.out: game name field key down!
I/System.out: game name field key up!
I/System.out: game name field key typed!

这是我的代码:

public class AccountScreen implements Screen {


final PieTherapy game;
private Stage stage;

private TextField gameNameField;

public AccountScreen(final PieTherapy game) {
    this.game = game;
    initialize();
}

private void initialize() {

    Viewport vp = new StretchViewport(PieTherapy.WORLD_WIDTH, PieTherapy.WORLD_HEIGHT, game.cam);
    stage = new Stage(vp);

    Gdx.input.setInputProcessor(stage);

    TextField.TextFieldStyle tfs = new TextField.TextFieldStyle();
    tfs.font = game.fontTitle;
    tfs.fontColor = Color.WHITE;
    tfs.background = new TextureRegionDrawable(new TextureRegion(game.assets.get("menus/textline.png", Texture.class)));
    tfs.focusedBackground = new TextureRegionDrawable(new TextureRegion(game.assets.get("menus/textline-selected.png", Texture.class)));
    tfs.cursor = new TextureRegionDrawable(new TextureRegion(game.assets.get("menus/cursor.png", Texture.class)));

    gameNameField = new TextField("", tfs);
    gameNameField.setWidth(PieTherapy.WORLD_WIDTH * .80f);
    gameNameField.setFocusTraversal(true);
    gameNameField.setPosition(PieTherapy.WORLD_WIDTH *.05f, game.WORLD_HEIGHT * .68f);
    // see if the player information has already been entered (edit mode)
    gameNameField.setText(game.primaryPlayer.gameName);
    gameNameField.addListener(new InputListener(){
        @Override
        public void touchUp (InputEvent event, float x, float y, int pointer, int button) {
            System.out.println("game name field touch up!");
        }
        @Override
        public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
            System.out.println("game name field touch down!");
            return true;
        }

        @Override
        public boolean keyDown(InputEvent event, int keycode) {
            System.out.println("game name field key down!");
            return super.keyDown(event, keycode);
        }

        @Override
        public boolean keyUp(InputEvent event, int keycode) {
            System.out.println("game name field key up!");
            return super.keyUp(event, keycode);
        }

        @Override
        public boolean keyTyped(InputEvent event, char character) {
            System.out.println("game name field key typed!");
            return super.keyTyped(event, character);
        }
    });

    gameNameField.getOnscreenKeyboard().show(true);
    gameNameField.setCursorPosition(gameNameField.getText().length());

    stage.addActor(gameNameField);

    stage.setKeyboardFocus(gameNameField);
}

@Override
public void show() {

}

@Override
public void render(float delta) {
    Gdx.gl.glClearColor(0, 0, 0f, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    game.batch.begin();
    game.font.draw(game.batch, "Your name in the game! You can stick with the\nautomatically generated" +
                    "one or change to your own.\n Red: name is not available, " +
                    "green: available.",
            PieTherapy.WORLD_WIDTH *.36f,
            PieTherapy.WORLD_HEIGHT *.93f);

    game.batch.end();

    update(delta);
}

private void update(float delta) {

    stage.act(delta);

    stage.draw();

    game.batch.begin();

    game.batch.end();

}

@Override
public void resize(int width, int height) {

}

@Override
public void pause() {

}

@Override
public void resume() {

}

@Override
public void hide() {

}

@Override
public void dispose() {

}
}

LibGDX版本:1.9.6 RoboVM (MobiDevelop) 版本:2.3.1

我想我总能滚动自己的屏幕键盘...

只是想跟进以防将来有人发现自己在这里。我最终创建了自己的屏幕键盘,我无法让事件在 iOS 中持续工作。

如果以后有人有什么想补充的,我会签到接受答案。