Titanium Community Questions & Answer Archive

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

Orientation oddity: Switches back to portrait when tab is changed


I just added support to my app for orientation change and I'm experiencing a couple of anomalies. The first is that when I've changed orientation to landscape, then hit a tab, it switches by itself back to portrait view. Views within the same tab are not affected this way. I suspect that there is something you can do with an event listener for the tabGroup but I haven't seen anything about how to do this yet.

The other issue is related, and more troubling by virtue of the fact that it's intermittent: Sometimes when the orientation switches back to portrait, the tabGroup does not resize properly so that I end up with one of the four tabs mostly hidden off to the right at the bottom of the screen.

I've included my DeviceOrientation class below. I instantiate this on every page, then call its 'get' method in the window's 'focus' listener, as well as the Ti.Gesture 'orientationchange' listener.

Thanks in advance,


function DeviceOrientation(arg) {
    //*** Create a reference to this instance;
    var me = this;
    this.arg = arg;
    this.window = (typeof(arg.window) == "undefined") ? null : arg.window;
    this.device = (typeof(arg.device) == "undefined") ? null : arg.device;
    this.iPhone320BarImage = (typeof(arg.iPhone320BarImage) == "undefined") ? null : arg.iPhone320BarImage;
    this.iPhone480BarImage = (typeof(arg.iPhone480BarImage) == "undefined") ? null : arg.iPhone480BarImage;

    if (this.window != null) {
        this.window.orientationModes = [

    DeviceOrientation.prototype.get = function () {
        var o = Titanium.Gesture.orientation;
        //Ti.API.info("Orientation: " + o);
        if (o == Titanium.UI.PORTRAIT || o == Titanium.UI.UPSIDE_PORTRAIT) {
            if (me.device == "iphone") {
                me.window.barImage = me.iPhone320BarImage;
        if (o == Titanium.UI.LANDSCAPE_LEFT || o == Titanium.UI.LANDSCAPE_RIGHT) {
            if (me.device == "iphone") {
                me.window.barImage = me.iPhone480BarImage;
— asked December 2nd 2010 by Mark Pemburn
  • iphone
  • orientation
  • tabgroup

1 Answer

  • Oh well, looks like once again I have to answer my own question. (Does anyone with experience actually read these questions?)

    This is a workaround and has a kind of kludgey feel to it but if you add:

    Ti.UI.orientation = Titanium.Gesture.orientation;

    . . . someplace in your page so that it gets called when the page loads, it will force the screen to orient to the mode that it's already set to. You say, "Huh?" Apparently, the news that we're in landscape mode doesn't get passed to the tab immediately the first time you enter it so you have to poll the Gesture object to see what it knows about the current orientation.

    The reason I say this is kludgey is that if you're in landscape mode and you switch to different tab, it'll try to go back to portrait mode until it hit's the line above, then switch back to landscape. Too bad there's no way to test before the page loads. Something to work on, SDK guys. (You're doing great so far – just a few things to fix).

    — answered December 21st 2010 by Mark Pemburn
    1 Comment
    • I was experiencing a similar issue and this fixed it! Great work, thanks!

      — commented December 25th 2010 by Otacon Overdrive
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.