如何在旋转时修复native.newTextField方向

时间:2016-04-01 08:16:44

标签: lua corona

我们的应用仅支持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 
  

这是正确的布局,但native.newTextField内的文字已被删除,

enter image description here

  

这是旋转(landscapeRight

后发生的事情

enter image description here

我该如何解决这个问题?

3 个答案:

答案 0 :(得分:1)

好。我找到了解决方案:

settings = 
{
    ...

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

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

答案 1 :(得分:0)

在build.setting中包含此内容

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

答案 2 :(得分:0)

我不知道native.newTextField()是如何硬化的。我在上面的评论中已经要求提交关于此的错误报告。我确定当你说要在build.settings文件中同时支持纵向和横向方向时,textFields正确旋转。

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

罗布