Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

How to detect app start orientation

When I start the app, the splashscreen show in the correct orientation, but no the background of my main window, is there a way to detect the start orientation ?.

Thanks in advanced.

— asked October 27th 2010 by Esteban Fernandez
  • ipad
  • orientation

3 Answers

  • You can check the current orientation by looking at Ti.UI.orientation.

    You can monitor orientation change doing something like this:

    Ti.Gesture.addEventListener('orientationchange', function(e) {
      // Do something about orientation
    — answered October 27th 2010 by John McKnight
    • Than's is when the App it's already loaded, what I need is detect if the App is starting Portrait or Landscape (before change when load)

      — commented October 27th 2010 by Esteban Fernandez
    • It looks like Ti.UI.orientation was discontinued? I can't find it in the API now. I'm pretty sure it used to be there. But now when I log it it just returns: undefined

      — commented March 22nd 2011 by Daniel Tome
    • Daniel, It's "Titanium.UI.orientation".

      — commented May 19th 2011 by Mike Tyranski
  • A workaround (aka Hack) would be to do this:

    Call CurrentOrientation() instead of Ti.UI.orientation. This will return 3 if it's landscape or 1 if portrait.
    The downside is you don't know which way it's facing (left/right or up/down)

    function CurrentOrientation()
        var w = Titanium.Platform.displayCaps.platformWidth;
        var h = Titanium.Platform.displayCaps.platformHeight;
        if( w > h){
            return 3;
            return 1;
    — answered March 22nd 2011 by Daniel Tome
  • In more recent versions of Titanium you can use the Ti.Gesture.orientation property.

    — answered September 22nd 2013 by Chris Rose
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.