简体   繁体   English

如何使用UIView.hidden属性更改视图的可见性

[英]How to use the UIView.hidden property to change visibility of views

In my IOS application, I need to show a drop-down menu when the menu button is pressed and hide it when the menu button is pressed again. 在我的IOS应用程序中,我需要在按下菜单按钮时显示一个下拉菜单,并在再次按下菜单按钮时隐藏它。 I tried changing the hidden status to false and true as in the code below however that doesn't seem to work. 我尝试将隐藏状态更改为false和true,如下面的代码所示,但这似乎不起作用。

if (menuButtonActive == false)
{
    menuButtonActive = true;

    DropMenu.Hidden = true;

}
if (menuButtonActive == true)
{
    menuButtonActive = false;
    DropMenu.Hidden = false;
}

Thanks to anyone that helps! 感谢任何有帮助的人!

It's just simple, try this: 这很简单,请尝试以下操作:

In Swift: 在Swift中:

yourView.isHidden = true //or false

In Objective-C: 在Objective-C中:

yourView.hidden = YES; //or NO;

In C#: 在C#中:

yourView.Hidden = true; //or false;

In your case you are doing it right, but the problem is you are using only if in both cases. 在你的情况你正在做的是正确的,但问题是你只使用if在这两种情况下。 You have to use else if for second if condition in order to achieve the desired result. 您必须在第二个if条件中使用else if才能达到所需的结果。

Otherwise the second if condition will be always true and get executed you will see no effect of first if block. 否则,第二个if条件将始终为true并被执行,您将看不到第一个if块的影响。

For Your Case: 对于您的情况:

It should be like: 应该是这样的:

menuButtonActive = !menuButtonActive
DropMenu.Hidden = menuButtonActive

Hope this help you! 希望这对您有所帮助! :) :)

look at follow code , add a else 查看以下代码,添加其他

if (menuButtonActive == false)
{
    menuButtonActive = true;

    DropMenu.Hidden = true;

}
else if (menuButtonActive == true)
{
    menuButtonActive = false;
    DropMenu.Hidden = false;
}

It must be simple 一定很简单

menuButtonActive = !menuButtonActive;
DropMenu.Hidden = menuButtonActive;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 更改网格可见性属性 - Change Grid Visibility property 有没有办法通过其子项的可见性属性隐藏 ListBoxItem - Is there a way to hidden ListBoxItem by Visibility property of it's child 如何将“可见性窗口”属性从一种形式更改为另一种形式? - How to Change a Visibility Window property from the one form to another? 如何在应用程序运行时更改用户控件中按钮的可见性属性? - how to change the Visibility Property of button in the user control in the run time of the application? 如何使用C#中的visible属性创建一个函数来更改任何给定对象的可见性? - How to create a function to change the visibility of any given object with the visibility property in C#? ASP.NET如何将“隐藏”字段和具有可见性的文本框呈现为false? - How ASP.NET will render Hidden field and a textbox with visibility property as false? 如何使用UWP应用程序中的后退功能来更改网格的可见性? - How to use the back function in UWP apps to change visibility of a grid? 如何访问ListBoxItems的Visibility属性 - How to access Visibility property of the ListBoxItems 属性更改KnockoutJs的可见性未更新 - Visibility not being updated on property change KnockoutJs 如何在Xamarin中将UIView设置为隐藏 - How can I set a UIView to hidden in Xamarin
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM