Iphone 如何在钛合金中隐藏/显示视图?

Iphone 如何在钛合金中隐藏/显示视图?,iphone,titanium,titanium-mobile,Iphone,Titanium,Titanium Mobile,我不熟悉钛 我有3个视图,想隐藏在按钮上显示该视图点击iPhone应用程序 您知道如何实现这一点吗?您可以非常轻松地隐藏/显示视图,下面是一个自包含的示例: var win = Ti.UI.createWindow(); var view = Ti.UI.createView({ width : 100, height : 100, backgroundColor : 'red' }); var redView = Ti.UI.createView({ title

我不熟悉钛

我有3个视图,想隐藏按钮上显示该视图点击iPhone应用程序


您知道如何实现这一点吗?

您可以非常轻松地隐藏/显示视图,下面是一个自包含的示例:

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();

虽然另一个答案当然很有用,但还有两种(稍微)不同的方法可以做同样的事情,以防在使用show()和hide()时Tianium会出现问题

您可以将不透明度设置为0,即使视图的visible属性设置为true,由于不透明度级别完全不存在,因此它仍将不可见。如果您希望某些内容可见,但不可单击(通过将视图放置在不透明度为零的视图后面),此选项非常有用

//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);
});

你能说得更具体些吗?你到底想做什么,你有没有试过任何代码等等。。
//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);
});