在 Xamarin.iOS 中隐藏和显示控件 [英] Hiding and Showing controls in Xamarin.iOS

查看:26
本文介绍了在 Xamarin.iOS 中隐藏和显示控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Xamarin.iOS 初学者.我也没有太多的 iOS 原生体验.我试图隐藏和显示包含 UILabel 和 UITextField 的 UIView.尽管视图的 hidden 属性设置为 true,但它仍然占用屏幕空间.如何删除这个空间?如果我尝试将宽度约束设置为 0 以隐藏它,然后将其设置回其原始值以显示它,则它不起作用.它继续保持在 0.

另一个问题 - 当打开和关闭其可见性时,视图是否会保持其状态和行为?

在此先感谢您的帮助..

解决方案

如果没有您的代码,就很难说出解决方案.但是从您的问题中,我可以看到一些解决方案,例如:

  1. 您可以尝试在主线程中更改约束,更改约束后您需要调用 LayoutIfNeeded()

    [Foundation.Export("layoutIfNeeded")]public virtual void LayoutIfNeeded()

I am a Xamarin.iOS beginner. I don't have much iOS native experience too. I am trying to hide and show a UIView which contains a UILabel and a UITextField. Though the hidden property is set to true for the view, it still occupies space in the screen. How do I remove this space? If I try to set the width constraints to 0 to hide it and then later, set it back to its original value to show it, it doesn't work. It continues to remain at 0.

Another question - will the view retain its state and behaviour when toggling on and off its visibility?

Thanks in advance for all the help..

解决方案

Without your code it's difficult to tell the solutions. But from your question I can see few solutions like:

  1. You can try changing constraint in main thread and after changing constraint you need to call LayoutIfNeeded()

    [Foundation.Export("layoutIfNeeded")] public virtual Void LayoutIfNeeded ()

  2. Other than that you can use horizontal UIStackView which will make UIView's width to 0 while hiding and back to original while showing.

这篇关于在 Xamarin.iOS 中隐藏和显示控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆