如何修复 native.newTextField 旋转方向

How to fix native.newTextField orientation on rotation

我们的应用程序仅支持 portrait,我们正在手动旋转一些对象,但我们有这个 native.newTextField

-- setupTextField
function setupTextField()

    local txNameBG = display.newImageRect( "images/login/login-input-bg.png", 225, 30 )
    txNameBG.x = _gameCenter.x
    txNameBG.y = _gameCenter.y
    sceneGroup:insert(txNameBG)
    _events.fixRotate(txNameBG)

    if (txName == nil) then
        txName = native.newTextField( _gameCenter.x, _gameCenter.y, 225, 30 )
        txName.hasBackground = false
        txName.inputType = "default"
        txName.placeholder = "INSERT NAME"
        txName.align = "center"
        txName.font = native.newFont( native.systemFont, 15 )
        txName:setTextColor( 163, 25, 12 )
        txName:addEventListener( "userInput", _events.textListener )
        sceneGroup:insert(txName)
        -- _events.fixRotate(txName)

    end 

end

这是我们用于旋转对象的函数(仅那些原生对象。*)没有响应。

eventClass.fixRotate = function ( obj )

    obj:rotate(90)
    obj.isFixedRotation = true
    -- obj.angularVelocity = 0

end 

This is the correct layout, but the text inside the native.newTextField was cut,

This is what happen after rotating(landscapeRight)

我该如何解决这个问题?

将此添加到您的 build.setting

settings = {
    orientation =
    {
        default = "landscapeRight",
        content = "landscapeRight",
        supported = { "landscapeRight", "portrait" },
    },
}

好的。我找到了解决方案:

settings = 
{
    ...

    orientation =
    {
        // I changed
        // supported = { "portrait" }, to
        //
        supported = { "portrait", "landscapeRight", "landscapeLeft", "portraitUpsideDown"}
    }
    ...
}

此外,我发现被剪切的文本仅出现在 Corona Simulator 中,但在真实设备(我的情况是 iP6plus)中它看起来非常好。因此,作为我的个人建议,请始终在真实设备上测试您的应用程序。

我不知道 native.newTextField() 对手动旋转有多严格。我已经在上面的评论中要求获得关于此的错误报告。当您说要在 build.settings 文件中同时支持纵向和横向方向时,我确信 textFields 可以正确旋转。

我不确定你为什么要手动执行此操作而不是使用 onOrientation 事件重新布局页面而不是手动旋转所有对象。

罗布