Titanium Community Questions & Answer Archive

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

IPad Orientation done Right?

Hi,

please see Question -best-practice-for-project-structure for getting an overview to my project.

How should i do the Orientation changes? Right now i have two functions rotatePortrait() and rotateLandscape()which are called when the orientation is changed. I have one EventListener which is located in app.js at the end:

Ti.Gesture.addEventListener('orientationchange',function(e){
     // now do stuff... refresh etc..

    if(e.orientation == Titanium.UI.PORTRAIT 
       || e.orientation == Titanium.UI.UPSIDE_PORTRAIT){
        // Function that changes the left property of 
        // just about every item in the view
        app.config.rotatePortrait();
    }
    else if(e.orientation == Titanium.UI.LANDSCAPE_LEFT 
              || e.orientation == Titanium.UI.LANDSCAPE_RIGHT){
        app.config.rotateLandscape();
    }
    else{
        // Guess
        //app.config.rotatePortrait();
    }

});

These functions change every relevant sizes of all elements in the different windows (in every App-Part). This functions become bigger and bigger and so my question, is this usage correct?

Or should i used a separate EventListener for the orientation in every "App-Part-Main-Window?

Sorry for the maybe very stupid questions but i don´t find a good Best Practice for this Problem.

Thanks for your patience.

— asked July 30th 2010 by Christian Zacharias
  • iphone
  • mobile
  • orientation
  • orientationchange
1 Comment
  • Did you come to a conclusion. I handle things the same way previously all in app.js and looked to split items into window views however adding Ti.Gestures in each win seems to layer them anyway… and trying to remove the eventListener on blur etc didn't seem to work.

    — commented October 15th 2012 by david brewer

2 Answers

  • Hi,

    not sure about this one mate, currently my app is entirely made up of table views, so nothing changes on orientation change(yet).

    The only other object I have on the screen is the toolbar, I am using the flexible space button to keep this centered on the screen

    like so:

    var flex = Ti.UI.createButton({
    systemButton:Ti.UI.iPhone.SystemButton.FLEXIBLE_SPACE
    });
    var edit = Ti.UI.createButton({
    systemButton:Ti.UI.iPhone.SystemButton.EDIT
    });
    
    var toolbar = Ti.UI.createToolbar({
        items:[flex, edit, flex],
        top:0,
        opacity:0.5
    });    
    detailWindow.add(toolbar);
    

    I am currently building some elements that will be absolute positioned, so if i come up with anything ill let you know

    in terms of events in general though, I tend to put them inside the file they are effecting

    — answered July 30th 2010 by Richie Mortimer
    permalink
    0 Comments
  • This might Help… it's working for me:

    function detectLayout(e){
     if(Titanium.Platform.displayCaps.platformWidth<Titanium.Platform.displayCaps.platformHeight){
      //is Portrait
     }else{
      //is Landscape
     }
    }
    detectLayout({orientation:Titanium.Gesture.orientation});
    Ti.Gesture.addEventListener('orientationchange',detectLayout);
    

    This is to avoid the unknown and face up/ face down modes….. basically if the width is higher than the height it is landscape…. if not then… guess!! :P
    Back to the roots!

    — answered January 26th 2011 by Marco Chacon
    permalink
    1 Comment
    • not sure why you got down voted. This helped me trying to detect what the heck was going on in this weird face up mode

      — commented March 5th 2015 by Ronnie Swietek
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.