Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hiding view in stack view in iOS 10

When I hide a UIView inside UIStackview, on iOS 11 it nicely removes the gap and brings the adjacent UIViews closer inside the UIStackView. However, on iOS 10 it will not move the adjacent views and just leave the gap for the hidden view. Is there a way to get around it without having to manually move the views.

like image 789
Kashif Avatar asked Nov 25 '17 17:11

Kashif


People also ask

How do I hide view in stack view?

In order to hide a view within a stack view, set the contained view's hidden property to true , and the stack view handles the rest. This is how you'll fix the spacing under the WEATHER label when the user hides the text below it.

What is stack view in IOS?

Overview. Stack views let you leverage the power of Auto Layout, creating user interfaces that can dynamically adapt to the device's orientation, screen size, and any changes in the available space. The stack view manages the layout of all the views in its arrangedSubviews property.

How do I use stack view auto layout?

fill. A layout where the stack view resizes its arranged views so that they fill the available space perpendicular to the stack view's axis. The simplest of the alignments, . fill constrains the leading/trailing edges of each arranged subview to the leading/trailing edge of the stack view.

How do I hide a view in a stack view?

In order to hide a view within a stack view, set the contained view’s hidden property to true, and the stack view handles the rest. This is how you’ll fix the spacing under the WEATHER label when the user hides the text below it.

How do I animate a hidden view in iOS?

In iOS, the view’s hidden property is normally not animatable. However, this property becomes animatable for views as soon as they are placed in a stack’s arranged views array. The actual animation is managed by the stack, not the view. Use the hidden property to animate adding views to or removing them from the stack.

How do I align a view inside a stack view?

Align any contained views inside a stack view by using a combination of the alignment property, Spacer, and Divider views. In the previous example layout, the VStack that contains the two Text views uses the leading alignment: The alignment property doesn’t position the VStack inside its container; instead, it positions the views inside the VStack.

How to position a stack view within its parent view?

While the Stack View has total control over the layout of any subview (based on properties such as Axis and Distribution ), you still need to position the Stack View ( UIStackView) within its parent view using Auto Layout and Size Classes.


1 Answers

Have you added your own height constraint to the UIView? It will cause a conflict with the constraint height = 0 generated by the UIStackView when the UIView is hidden on iOS 10. Just lower the Priority of UIView height constraint (e.g. 999) and the UI will update properly.

enter image description here

like image 55
Will Avatar answered Nov 05 '22 17:11

Will