Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Reload screen on rotate...

Ok folks…

So I need to somehow refresh the screen on rotate (iPhone). I'm using percentages for my widths - but that's not enough as the screen doesn't actually recalculate the widths when the hardware is rotated.

The parent to this page has an orientationchange event listener. That seems like a good place to do the reFresh… but I don't know how to do it.

I'm pretty sure I had this working at one point on an ipad app with no effort at all… I just set the width to some math based on the window width and it worked. But it doesn't seem to want to do that here.

My code is below.

var win = Titanium.UI.currentWindow;

var scrollView1 = Titanium.UI.createScrollView({
     contentWidth:'auto',
     contentHeight:'auto',
     showVerticalScrollIndicator:true,
     showHorizontalScrollIndicator:true,
     layout:'vertical'
    });


var padding = 10;

var view_itemtitle = Ti.UI.createView({
    top:padding,
    backgroundColor:'#ffffff',
    borderRadius:10,
    width: '90%',
    height:'auto'

});

var label_itemtitle = Titanium.UI.createLabel({
        top:padding,
        text:win.itemtitle + 'nnn',
        color:'#003399',
        width: '90%',
        font:{fontSize:18,fontWeight:'bold',fontFamily:'Helvetica Neue'},
        height: 'auto'
});

view_itemtitle.add(label_itemtitle);
scrollView1.add(view_itemtitle);


var view_itemdesc = Ti.UI.createView({
    top:padding,
    backgroundColor:'#ffffff',
    borderRadius:10,
    width: '90%',
    height:'auto'

});

var label_itemdesc = Titanium.UI.createLabel({
        top:padding,
        text:win.itemdesc + 'nnn',
        color:'#000000',
        width: '90%',
        font:{fontSize:14,fontWeight:'normal',fontFamily:'Helvetica Neue'},
        height: 'auto'
});

view_itemdesc.add(label_itemdesc);
scrollView1.add(view_itemdesc);

win.add(scrollView1);
— asked May 2nd 2010 by Doug Meade
  • orientation
  • orientationchange
  • refresh
  • reload
  • rotate
0 Comments

7 Answers

  • You don't need to reload, you need to reset the percentages.

    — answered June 3rd 2010 by Joshua Kehn
    permalink
    2 Comments
    • Or left/right - e.g. for the example above

      Titanium.Gesture.addEventListener('orientationchange', function(e){
                  scrollView1.left = 0; 
                  scrollView1.right = 0; 
      });
      

      — commented July 27th 2011 by Jeff Antram
    • As a heads up to people finding this page looking for how to use orientationchange, here's some additional info.

      Ti.Gesture is a global object, and this event will keep the memory of your window from being released. You'll need to add a removeEventListener when the window is closed, and thus shouldn't use an anonymous function.

      //listen for orientation change
          Ti.Gesture.addEventListener('orientationchange', onRotate);
          function onRotate(e){
              //do it
          }
          //prepare to destory listener
          win.addEventListener('close', destroy);
          function destroy(e){
              //remove event listener
              Ti.Gesture.removeEventListener('orientationchange', onRotate);
          }
      

      …as for the specific problem asked in this post, you could put the ui elements that need to have their positions refreshed into an array, and loop through the array and reset their properties to fit the width of your device.

      — commented January 27th 2012 by Digital Surgeons
  • Try adding this at the bottom of your code to detect the orientation change

    Ti.Gesture.addEventListener('orientationchange',function(e){        
    
         Ti.API.info('the orientation changed to  '+e.orientation);
         // now do stuff... refresh etc..
    
    });
    
    — answered May 2nd 2010 by Kosso
    permalink
    0 Comments
  • Yeah I already have that.
    As I said:

    "The parent to this page has an orientationchange event listener. That seems like a good place to do the reFresh… but I don't know how to do it"

    I can't figure out the commands to put there that would cause the page to refresh.

    I'd love something like

    win.reLoad();

    but there seems to be no such functionality.
    How can I get the screen to refresh itself?

    Thanks!

    — answered May 2nd 2010 by Doug Meade
    permalink
    0 Comments
  • Anyone?

    Need to force a screen to fresh.

    Any ideas?

    — answered May 4th 2010 by Doug Meade
    permalink
    0 Comments
  • {removed}

    Duplicate answer.

    — answered June 3rd 2010 by Joshua Kehn
    permalink
    0 Comments
  • Doug,
    I am trying to do the same thing as you were, did you ever find an answer?

    Thanks!

    — answered December 1st 2010 by Pete Halatsis
    permalink
    0 Comments
  • Doug,
    I am trying to do the same thing as you were, did you ever find an answer?

    Thanks!

    — answered December 1st 2010 by Pete Halatsis
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.