Titanium Community Questions & Answer Archive

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

zIndex not working on iPhone

Hey guys..

Im curious, anyone know why this wont work?


var win = Titanium.UI.currentWindow;

var views = [];

// title control
var tb4 = Titanium.UI.createTabbedBar({
    labels: ['Tables', 'Fixtures'],
    index: 0,
    style: Titanium.UI.iPhone.SystemButtonStyle.BAR,
    width: 180
});

views[0] = Ti.UI.createView({
    width: '100%',
    height: '100%',
    backgroundColor: '#124',
    zIndex: 1
});
win.add(views[0]);

views[1] = Ti.UI.createView({
    width: '100%',
    height: '100%',
    backgroundColor: '#624',
    zIndex: 0
});

win.add(views[1]);

tb4.addEventListener("click", function(e){
    for(var i = 0; i < views.length; i++){
        views[i].zIndex = 0;
    }
    views[e.index].zIndex = 999;
});

win.setTitleControl(tb4);
— asked September 10th 2010 by Stephen McElhinney
  • iphone
  • views
  • zindex
0 Comments

4 Answers

  • I think it's a bug. I don't know if it's fixed in 1.4.1 or not.
    Try to animate the zIndex instead of setting it. Take care to have a zIndex setup to have what to animate from.

    
     views[e.index].animate({zIndex:999});
    
    — answered September 10th 2010 by Dan Tamas
    permalink
    0 Comments
  • Hey guys..

    Figured it out. Didnt need zIndex at all, my bad. Code below in case anybody needs it.

    
    var win = Titanium.UI.currentWindow;
    
    var views = [];
    
    views[0] = Ti.UI.createView({
        width: '100%',
        height: '100%',
        backgroundColor: '#124',
        zIndex: 1
    });
    
    
    views[1] = Ti.UI.createView({
        width: '100%',
        height: '100%',
        backgroundColor: '#000',
        zIndex: 0
    });
    
    // Set a default view. 
    win.add(views[0]);
    
    // title control
    var tb4 = Titanium.UI.createTabbedBar({
        labels: ['Tables', 'Fixtures'],
        index: 0,
        style: Titanium.UI.iPhone.SystemButtonStyle.BAR,
        width: 180
    });
    
    win.setTitleControl(tb4);
    
    tb4.addEventListener("click", function(e){
        for(var i = 0; i < views.length; i++){
            win.remove(views[i]);
        }
        win.add(views[e.index]);
    });
    
    — answered September 13th 2010 by Stephen McElhinney
    permalink
    0 Comments
  • You might try instantiating the view you want on top last, like this:

    views[0] = Ti.UI.createView({
        width: '100%',
        height: '100%',
        backgroundColor: '#124',
        zIndex: 1
    });
    
    views[1] = Ti.UI.createView({
        width: '100%',
        height: '100%',
        backgroundColor: '#624',
        zIndex: 0
    });
    
    win.add(views[1]);
    win.add(views[0]);
    
    — answered September 10th 2010 by Clifton Labrum
    permalink
    0 Comments
  • hi,I've tried many times but it still don't work.No matter how I use the method :setZIndex or use the property:ZIndex ,results are always same.

    — answered April 2nd 2013 by zhang ting
    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.