ios 触摸按钮时隐藏一个视图并取消隐藏另一个视图

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7549076/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 21:38:26  来源:igfitidea点击:

Hide one view and unhide another upon touching a button

ioscocoa-touch

提问by philvitz

I have been creating "if/then" apps for android and now my boss want me to do the same for his iPad. I just need to figure out how to code so that when the buttons are clicked, it hides the current view (text and button) and reveals the next set of text and buttons.

我一直在为 android 创建“if/then”应用程序,现在我的老板希望我为他的 iPad 做同样的事情。我只需要弄清楚如何编码,以便在单击按钮时隐藏当前视图(文本和按钮)并显示下一组文本和按钮。

回答by Dyldo42

Make sure your two sets of text/buttons are in two UIViews (I will refer to these as 'viewOne' and 'viewTwo'), when you want to swap your views, use this code:

确保您的两组文本/按钮位于两个 UIView 中(我将它们称为“viewOne”和“viewTwo”),当您想要交换视图时,请使用以下代码:

[viewOne setHidden:[viewTwo isHidden]];
[viewTwo setHidden:![viewTwo isHidden]];

It's not the most understandable way to do this, but it's one of the shortest. For something easier to read:

这不是最容易理解的方法,但它是最短的方法之一。为了更容易阅读:

if ([viewOne isHidden]) {
    [viewOne setHidden:NO];
    [viewTwo setHidden:YES];
} else {
    [viewOne setHidden:NO];
    [viewTwo setHidden:YES];
}

Either will work, it just depends on how you like to write your code.

两者都可以,这取决于您喜欢如何编写代码。