iPad Orientation problem when slightly tilting forward/backward

You must Login before you can answer or comment on any questions.

I'm using the below snippet to change the layout of the iPad in a splitveiw. It works fine on the simulator and on a older iPad but on the iPad 2 when I have it on landscape facing at me and then slightly tilt it forward/backwards the detailview changes back to the portrait orientation dimensions but the masterview is ok. It's really annoying me. Can anyone help?

function getOrientation(o) {
    switch (o) {
        case Titanium.UI.PORTRAIT: return 'portrait';
        case Titanium.UI.UPSIDE_PORTRAIT: return 'portrait';
        case Titanium.UI.LANDSCAPE_LEFT: return 'landscape';
        case Titanium.UI.LANDSCAPE_RIGHT: return 'landscape';
    }
}
  Ti.Gesture.addEventListener('orientationchange',function(e){
  var orientation = getOrientation(e.orientation);
if (orientation == 'portrait') {
//do something
 } else if (orientation == 'landscape') {
//do something
 }
});

— asked 1 year ago by Somme Sakounthong
3 Comments
  • i'm having the same problem, very frustrating...

    — commented 12 months ago by Luc Succes

  • Me too.. its driving me crazy. In fact, its basically a show stopper even for my app.

    — commented 12 months ago by E B

  • did you try the answers below? we are using the approach below in an app that is in production and it is working fine on 2.0.2GA

    — commented 12 months ago by Aaron Saunders

2 Answers

I had the same problem, and ended up using these:

Ti.Gesture.addEventListener('orientationchange', function(e){
  if (e.orientation == Titanium.UI.PORTRAIT || e.orientation == Titanium.UI.UPSIDE_PORTRAIT) {
    // do something
  } else if (e.orientation == Titanium.UI.LANDSCAPE_LEFT || e.orientation == Titanium.UI.LANDSCAPE_RIGHT) {
    // do something
  }
});

— answered 1 year ago by Edwin Chan
answer permalink
7 Comments
  • That does the same thing. Has anyone else had a similar problem? one way to remotely replicate it on the simulator is to turn on the lock. Once you slide to unlock on the landscape orientation it will squeeze the detailview into portrait.

    — commented 1 year ago by Somme Sakounthong

  • I'm having the same issue with my iPad app. I haven't been able to figure out how to make it ignore the FACEUP orientation.

    — commented 1 year ago by Justin Brown

  • Any luck with this issue, Somme? I was hoping the latest SDK would take care of it, but no such luck. It first presented itself as a problem in my app as a flicker with some of the background images. I narrowed it down to the orientationchange by telling the app to blur my search field on orientation change.

    My code is identical to Somme's above so the keyboard should only disappear when changing from portrait to landscape. Instead, if I go from a standard landscape view to laying the iPad down flat, the search field will lose focus causing the keyboard to disappear. This happens somewhere around 60 degrees, so if I have the iPad laying in my lap trying to type in the search field, it keeps losing focus as it detects a switch between landscape and what I assume is the FACEUP orientation.

    I've tried several solutions suggested in the Q&A, but nothing has worked yet. Any ideas?

    — commented 1 year ago by Justin Brown

  • Show 4 more comments

Your Answer

Think you can help? Login to answer this question!