KBrianJ
KBrianJ

Reputation: 55

Handling Orientation Change for iOS in Titanium Studio?

I've read the docs and have the code below but am obviously missing something.

    Ti.Gesture.addEventListener('orientationchange', function (ev) {
      if (Ti.Gesture.isLandscape(ev.orientation)) {
        // Update your UI for landscape orientation
      } else {
        // Update your UI for portrait orientation
      }
    });

What am I supposed to be doing to update my UI as mentioned in the comments above? I've got a simple TabGroup, with WebViews inside. What am I missing?

Upvotes: 0

Views: 1019

Answers (2)

Muhammad Adnan
Muhammad Adnan

Reputation: 2668

KitchenSink Get Orientations

look at this example .it will be helpful

Upvotes: 2

sundar nataraj
sundar nataraj

Reputation: 8702

if you want to have orentaion change to your window

use this

var window = Ti.UI.createWindow({
   orientationModes: [
      Ti.UI.LANDSCAPE_LEFT,
      Ti.UI.LANDSCAPE_RIGHT,
      Ti.UI.PORTRAIT,
      Ti.UI.UPSIDE_PORTRAIT
     ]

});

this code tells that your window now have all oreintaions

now you need to make some ui changes say in portaint you have width :320 and height 480

you need know when the change was happened. soo oreintchange event is used

Ti.Gesture.addEventListener('orientationchange', function(e) {
      Titanium.API.info('Orientation changed to '+e.orientation);
        if(e.orientaion=="Ti.UI.PORTRAIT")
        {

                width:320,height:480
        }
    else{

  width:480,height:320

 }



 });

Upvotes: 2

Related Questions