Question

I'm doing an application for Android and IOS. In this application, I have a window, and I add/remove different views with the content.

I want that the first view will be only in portrait mode, whereas the rest of the views can be in any orientation.

How can I do it?

With titanium SDK 3.1.2 it works more or less on IOS:

My window:

var appWindow = Titanium.UI.createWindow({    
    top : 0,
    left : 0,
    height : utils.getScreenHeight(),
    width : utils.getScreenWidth(),    
    backgroundColor : "#393a3a",
    //fullscreen : true,    
    orientationModes : [Ti.UI.PORTRAIT, Ti.UI.UPSIDE_PORTRAIT],    
});

Then, when I want to load a view:

var openWindow = function(e) {    
    appWindow.orientationModes = [Ti.UI.PORTRAIT, Ti.UI.UPSIDE_PORTRAIT, Ti.UI.LANDSCAPE_LEFT, Ti.UI.LANDSCAPE_RIGHT];

    if (e.win == 'Home') {
        Titanium.UI.orientation = Titanium.UI.PORTRAIT;
        appWindow.orientationModes = [Titanium.UI.PORTRAIT];
        orientacion = 0;
        activeView = Home.Constructor(appWindow);
    } else if (e.win == 'configuracion') {
        Titanium.UI.orientation = Titanium.UI.PORTRAIT;
        orientacion = 0;
        appWindow.orientationModes = [Titanium.UI.PORTRAIT];
        activeView = Configuracion.Constructor(appWindow);
    } else if (e.win == 'Circle') {
        activeView = Circle.Constructor(appWindow);
    }
    appWindow.add(activeView);
};

Now, I want to use SDK 3.1.3 to support IOS 7, and it doesn't work, none of the views allow to rotate.

Do you know how I can do this?

Thank you very much

Was it helpful?

Solution

I did not have any luck with changing a windows orientationModes on runtime too. The docs say that the window property orientationModes as well as its method setOrientationModes have to be set before opening the window.

So switching from views to windows is not an option?

If you want a window to allow orientations different from those defined in tiapp.xml, you have to set orientationModes on every window individually:

// This window allows orientations defined in tiapp.xml
var appWin = Ti.UI.createWindow({
    backgroundColor = '#FFF'
});
appWin.open();

// This window is portrait only
var win = Ti.UI.createWindow({
    backgroundColor: '#FFF',
    orientationModes: [Ti.UI.PORTRAIT]
});
win.open();

// If this window is opened it allows multiple orientations
var newWindow = Ti.UI.createWindow({
    backgroundColor: '#FFF',
    orientationModes: [Ti.UI.PORTRAIT, Ti.UI.LANDSCAPE_LEFT, Ti.UI.LANDSCAPE_RIGHT]
});
newWindow.open()

This is tested with SDK 3.1.3.


Edit
To make this work on Android, you have to force a heavyweight window by either setting fullscreen: true or navBarHidden: true

OTHER TIPS

You can create a custom AndroidManifest.xml and set screenOrientation attribute for the activities you want.-

android:screenOrientation="portrait"

More information here

With titanium SDK 3.1.2 I put the following code for:

Titanium.UI.orientation = Titanium.UI.PORTRAIT;
appWindow.orientationModes = [Titanium.UI.PORTRAIT];

and then, when you load other view, then put:

appWindow.orientationModes = [Ti.UI.PORTRAIT, Ti.UI.UPSIDE_PORTRAIT, Ti.UI.LANDSCAPE_LEFT, Ti.UI.LANDSCAPE_RIGHT];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top