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..
Even though you set the control's
Hidden
to true, it still exists there just can't be seen. So if your second control's constraints depend on the first one, it will not change its position.Which kind of constraints are you using?
If you use
NSLayoutAnchor
, you should disable the previous constraint before you want to modify it. For example:If you use
NSLayoutConstraint
, you can change the constant directly:Without your code it's difficult to tell the solutions. But from your question I can see few solutions like:
You can try changing constraint in main thread and after changing constraint you need to call
LayoutIfNeeded()
[Foundation.Export("layoutIfNeeded")] public virtual Void LayoutIfNeeded ()
Other than that you can use
horizontal UIStackView
which will makeUIView
's width to 0 while hiding and back to original while showing.