0yeoj
0yeoj

Reputation: 4550

How to fix native.newTextField orientation on rotation

Our app only support portrait and we are manually rotating some objects, but we are stock with this 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

Here is the function the we are using for rotating objects (only those native.*) are not responding.

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,

enter image description here

This is what happen after rotating(landscapeRight)

enter image description here

How do I fix this?

Upvotes: 2

Views: 133

Answers (3)

0yeoj
0yeoj

Reputation: 4550

Okay. I found a solution:

settings = 
{
    ...

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

Also, I found out that the text that was cut only occurs in Corona Simulator, but in real device (iP6plus in my case) it is looking pretty well. So as my personal advice, always test your app on a real device.

Upvotes: 1

Rob Miracle
Rob Miracle

Reputation: 3063

I don't know how hardened the native.newTextField() is to being rotated manually. I've asked in the comments above to get a bug report submitted on this. I know for certain that textFields rotate properly when you have said you want to support both Portrait and Landscape orientations in your build.settings file.

I'm unsure why you want to do this by hand instead of using an onOrientation event to re-layout the page instead of hand rotating all your objects.

Rob

Upvotes: 0

Amir
Amir

Reputation: 1683

Include this in your build.setting

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

Upvotes: 0

Related Questions