Different Ui Depending On Rotation And Device

I am creating a business app for someone and wondered if anyone had implemented different UI depending on rotation and device ?

I don’t mind have a iPhone and iPad version if that would be easier.

Am think along the line of the mail app and the way t changes when you go from Portrait to Landscape.

Any tips or code snippets appreciated.

Dave

If your app is not locked into either Portrait or Horizontal position I would think that display.contentWidth and display.contentHeight would change based on orientation.  I’ve not tested it, but this would seem to be rational behavior.

Then you could do:

[lua]

 if display.contentWidth > display.contentHeight then

     isLandscape = true

 end

[/lua]

Cheers Rob, that has helped.

I have also stuck a runTime event listener is each scene checking for orientation.

Pity you can’t have global listener functions (or maybe you can and I don’t know it). At the moment if there is something I want to change when the orientation changes, I have to go into every scene and change the listener.

Dave

Have you tried:

[lua]

 local function onOrient(event)
    if event.type == “portraitUpsideDown” then
        app.isUpsideDown = true
    else
        app.isUpsideDown = false
    end
    return true
 end

 Runtime:addEventListener(“orientation”, onOrient)

[/lua]

I used this in my Omniblaster game to implement an easter egg, er. testing feature :slight_smile:

I am using something simular at the moment. What I was saying though is I have that function in every scene, be great if I only needed to stick it in one place though. That is the only downside to Storyboard, before Storyboard where my whole game was in main.lua I could have just put that function in once. Dave

Just so you know, if you want to do this on Android tablets running Android 4.0+, you will have problems when the device orientation changes as the navbar at the bottom of the screen causes the screen to be incorrectly sized:

http://forums.coronalabs.com/topic/32916-android-orientation-switching-broken-on-nexus-7-style-displays-due-to-navigation-bar/

If your app is not locked into either Portrait or Horizontal position I would think that display.contentWidth and display.contentHeight would change based on orientation.  I’ve not tested it, but this would seem to be rational behavior.

Then you could do:

[lua]

 if display.contentWidth > display.contentHeight then

     isLandscape = true

 end

[/lua]

Cheers Rob, that has helped.

I have also stuck a runTime event listener is each scene checking for orientation.

Pity you can’t have global listener functions (or maybe you can and I don’t know it). At the moment if there is something I want to change when the orientation changes, I have to go into every scene and change the listener.

Dave

Have you tried:

[lua]

 local function onOrient(event)
    if event.type == “portraitUpsideDown” then
        app.isUpsideDown = true
    else
        app.isUpsideDown = false
    end
    return true
 end

 Runtime:addEventListener(“orientation”, onOrient)

[/lua]

I used this in my Omniblaster game to implement an easter egg, er. testing feature :slight_smile:

I am using something simular at the moment. What I was saying though is I have that function in every scene, be great if I only needed to stick it in one place though. That is the only downside to Storyboard, before Storyboard where my whole game was in main.lua I could have just put that function in once. Dave

Just so you know, if you want to do this on Android tablets running Android 4.0+, you will have problems when the device orientation changes as the navbar at the bottom of the screen causes the screen to be incorrectly sized:

http://forums.coronalabs.com/topic/32916-android-orientation-switching-broken-on-nexus-7-style-displays-due-to-navigation-bar/

Hit another problem now with rotating.

I have my navigation scene with a runtime event and if the device is rotated, everything moves all fine.

Problem is, if I have called say a login scene overlay and the device is rotated, the runtime in my navigation scene is never run, so I can move it.

Any ideas ?

Dave

Hit another problem now with rotating.

I have my navigation scene with a runtime event and if the device is rotated, everything moves all fine.

Problem is, if I have called say a login scene overlay and the device is rotated, the runtime in my navigation scene is never run, so I can move it.

Any ideas ?

Dave