Time for action – forcing an orientation change (all platforms)
Perform the following steps to force an orientation change for all platforms:
Add a button to the existing layout that will switch the layout to landscape:
var switchOrientation = Ti.UI.createButton({title: 'Make Landscape'}); switchOrientation.addEventListener('click', rotateLayout);
Add the button to the view. Note the highlighted line:
var layout = Ti.UI.createView({layout: 'vertical'}); layout.add(switchOrientation);
Create the
rotateLayout
function, which will be called when the button is clicked. Note the code hides the button when it is clicked. This is not required; it was added because the button isn't needed when the window is in landscape layout!function rotateLayout() { win1.orientationModes = [Ti.UI.LANDSCAPE_LEFT]; switchOrientation.hide(); }
Run the app!
What just happened?
You added code to rotate the layout of the screen to landscape. This will happen regardless of the orientation of the device. The following...