IPad Orientation done Right?
Hi,
please see Question -best-practice-for-project-structure for getting an overview to my project.
How should i do the Orientation changes? Right now i have two functions rotatePortrait()
and rotateLandscape()
which are called when the orientation is changed. I have one EventListener which is located in app.js at the end:
Ti.Gesture.addEventListener('orientationchange',function(e){
// now do stuff... refresh etc..
if(e.orientation == Titanium.UI.PORTRAIT
|| e.orientation == Titanium.UI.UPSIDE_PORTRAIT){
// Function that changes the left property of
// just about every item in the view
app.config.rotatePortrait();
}
else if(e.orientation == Titanium.UI.LANDSCAPE_LEFT
|| e.orientation == Titanium.UI.LANDSCAPE_RIGHT){
app.config.rotateLandscape();
}
else{
// Guess
//app.config.rotatePortrait();
}
});
These functions change every relevant sizes of all elements in the different windows (in every App-Part). This functions become bigger and bigger and so my question, is this usage correct?
Or should i used a separate EventListener for the orientation in every "App-Part-Main-Window?
Sorry for the maybe very stupid questions but i don´t find a good Best Practice for this Problem.
Thanks for your patience.
2 Answers
-
Hi,
not sure about this one mate, currently my app is entirely made up of table views, so nothing changes on orientation change(yet).
The only other object I have on the screen is the toolbar, I am using the flexible space button to keep this centered on the screen
like so:
var flex = Ti.UI.createButton({ systemButton:Ti.UI.iPhone.SystemButton.FLEXIBLE_SPACE }); var edit = Ti.UI.createButton({ systemButton:Ti.UI.iPhone.SystemButton.EDIT }); var toolbar = Ti.UI.createToolbar({ items:[flex, edit, flex], top:0, opacity:0.5 }); detailWindow.add(toolbar);
I am currently building some elements that will be absolute positioned, so if i come up with anything ill let you know
in terms of events in general though, I tend to put them inside the file they are effecting
-
This might Help… it's working for me:
function detectLayout(e){ if(Titanium.Platform.displayCaps.platformWidth<Titanium.Platform.displayCaps.platformHeight){ //is Portrait }else{ //is Landscape } } detectLayout({orientation:Titanium.Gesture.orientation}); Ti.Gesture.addEventListener('orientationchange',detectLayout);
This is to avoid the unknown and face up/ face down modes….. basically if the width is higher than the height it is landscape…. if not then… guess!! :P
Back to the roots!