ios 如何在 Xcode 中显示/隐藏视图

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14118465/
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:41:14  来源:igfitidea点击:

How to show/hide view in Xcode

iphoneobjective-cioscocoa-touch

提问by Link

Good day..! I would like to ask some assistance no how to accomplish this task in xcode?

再会..!我想问一些帮助,不知道如何在 xcode 中完成此任务?

here's the scenario.. I have several buttons.. example below..

这是场景..我有几个按钮..下面的例子..

enter image description here

在此处输入图片说明

--> Sample
--> Sample
--> Sample

--> 示例
--> 示例
--> 示例

When you clicked on the first sample1, it will display a text containing information.. when you clicked again sample1, it will return to its original position..

当您点击第一个 sample1 时,它会显示一个包含信息的文本.. 当您再次单击 sample1 时,它将返回其原始位置..

Example when clicked

单击时的示例

--> Sample1
    --> Information here

--> Sample1
    --> 信息在这里

--> Sample2
--> Sample3

--> 样本 2
--> 样本 3

when clicked again

再次点击时

--> Sample1
--> Sample2
--> Sample3

--> 样本 1
--> 样本 2
--> 样本 3

Hope to hear from you soon..

希望早日收到你的消息..

Thanks,

谢谢,

Link

关联

回答by yurrriq

You can set the hidden property as mayuur and iDhaval suggested

您可以将隐藏属性设置为 mayuur 和 iDhaval 建议

view.hidden = YES; // or
view.hidden = NO;

or by calling setHidden:

或通过调用 setHidden:

[view setHidden:YES]; // or
[view setHidden:NO];

You could also set the alpha property of the view to 0.0f, but know that it still receives touch events.

您还可以将视图的 alpha 属性设置为 0.0f,但要知道它仍然接收触摸事件。

view.alpha = 0.0f; // or
[view setAlpha:0.0f];

See ColdLogic's answer to UIView hidden property...is there more to it?for code to animate the view "fading out," and Torsten Walter's answer to what's the difference between view's hidden = yes and alpha = 0.0ffor more information on the difference between setting the alpha property of a view to 0.0f and setting its hidden property to YES, and how iOS handles it in different contexts. The relevant Apple documentation on UIView could prove helpful, too.

请参阅 ColdLogic 对UIView 隐藏属性的回答...还有更多内容吗?有关为视图“淡出”设置动画的代码,以及 Torsten Walter 对视图的 hidden = yes 和 alpha = 0.0f 之间有什么区别的回答,以获取有关将视图的 alpha 属性设置为 0.0f 和设置其隐藏之间区别的更多信息属性为 YES,以及 iOS 在不同上下文中如何处理它。UIView 上的相关 Apple 文档也可能很有帮助。

In case you want to animate the showing and hiding of those informational text views by moving them, it wouldn't be much of a stretch to modify the code at iDev Recipes for implementing side swiping on a table as in the Twitter app. The full source code is available on GitHub.

如果您想通过移动这些信息文本视图来为它们的显示和隐藏设置动画,那么修改 iDev Recipes 中的代码来实现像 Twitter 应用程序中那样在桌子上实现侧滑不会很费力。GitHub 上提供了完整的源代码。

For more complex animation, reference Apple's Core Animation Programming Guide.

对于更复杂的动画,请参考 Apple 的 Core Animation Programming Guide。

Since I'm new to the site and it's limiting the number of hyperlinks I can include, you'll have to copy and paste the URLs next to the bullets.

由于我是该站点的新手,并且它限制了我可以包含的超链接数量,因此您必须复制并粘贴项目符号旁边的 URL。

回答by iDhaval

Please use the hiddenproperty with respective view on click event of button.

hidden在按钮的单击事件中使用具有相应视图的属性。