2013-05-13 45 views
2

嗨,我是新来的钛。如何隐藏show view钛?

我已经采取3看法,并希望隐藏显示按钮点击iPhone应用程序,查看。

任何想法如何实现这一目标?

在此先感谢。

+1

你能更具体?什么,你居然想做什么,你是否尝试过任何代码等等。 – Anand 2013-05-13 12:20:15

回答

1

可以隐藏/很容易,继承人一个自包含的例子表明一个观点:

var win = Ti.UI.createWindow(); 
var view = Ti.UI.createView({ 
    width : 100, 
    height : 100, 
    backgroundColor : 'red' 
}); 

var redView = Ti.UI.createView({ 
    title : 'Hide/Show Red View', 
    bottom : 0, 
    width : 200, 
    height : 35 
}); 
var visible = true; 
button.addEventListener('click', function(e) { 
    if(visible) { 
     redView.hide(); 
    } else { 
     redView.show(); 
    } 
    visible = !visible; 
}); 

win.add(redView); 
win.add(button); 
win.open(); 
1

虽然上面的答案肯定是有用的,其他两个(略)不同的做同样的事情的方法,只是柜面当您使用show()和hide()时,钛会翻转出来。

//Method 1, using part of Josiah Hester's code snippet 
var visible = true; 
button.addEventListener('click', function(e) { 
    if(visible) { 
     redView.setVisible(false); //This is the exact same thing as hide() method 
    } else { 
     redView.setVisible(true); //This is the exact same thing as show() method 
    } 
    visible = !visible; 
}); 

可以设置不透明度为0,即使该视图的Visible属性设置为,它将仍然是看不见的,因为不透明的完全不存在的水平。如果你想要的东西是可见的,但不能点击(通过放置一个视图为零的不透明度观点的背后,这非常有用。

//Method 2, same code section 
var opacity = 0; 
button.addEventListener('click', function(e) { 
    if(opacity) { 
     redView.setOpacity(0); //This is the NOT the same thing as hide() method 
    } else { 
     redView.setOpacity(1); //This is the NOT thesame thing as show() method 
    } 
    opacity = Math.abs(opacity - 1); 
}); 

干杯!