Skip to content

Instantly share code, notes, and snippets.

@jonalter
Created September 15, 2011 22:43
Show Gist options
  • Select an option

  • Save jonalter/1220697 to your computer and use it in GitHub Desktop.

Select an option

Save jonalter/1220697 to your computer and use it in GitHub Desktop.
iOS: open window on orientation change to landscape
// Must use TiSDK 1.8.0.v20110915133349 or newer
var tabGroup = Ti.UI.createTabGroup();
var win1 = Ti.UI.createWindow({
backgroundColor : 'white',
orientationModes : [Ti.UI.PORTRAIT]
});
var label1 = Ti.UI.createLabel({
text : 'I am a label'
});
win1.add(label1);
var tab1 = Ti.UI.createTab({
title : "tab1",
window : win1
});
tabGroup.addTab(tab1);
tabGroup.open();
var win2 = null;
Ti.Gesture.addEventListener('orientationchange', function(e) {
if(win2 === null) {
win2 = Ti.UI.createWindow({
backgroundColor : 'white',
orientationModes : [Ti.UI.LANDSCAPE_RIGHT, Ti.UI.LANDSCAPE_LEFT]
});
var label2 = Ti.UI.createLabel({
text : 'I am a label'
});
win2.add(label2);
}
if(e.orientation === Ti.UI.LANDSCAPE_RIGHT || e.orientation === Ti.UI.LANDSCAPE_LEFT) {
win2.open();
} else {
win2.close();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment