如何设置可视性GONE像IOS中的android?

Sid*_*hah 13 iphone android show-hide uilabel ios

有人知道隐藏标签的简单方法,让屏幕的其他视图使用空白处吗?在显示该视图时,反之亦然.类似于Android的setVisibility = GONE.

据我所知,使用setHidden = true只能隐藏屏幕上的视图,但不会重新排列它周围的任何内容.

谢谢

Fon*_*nix 12

在iOS上实现Androids .GON​​E功能的唯一方法是使用UIStackView

通过苹果文档

动态更改堆栈视图的内容无论何时添加,删除或插入已排列的视图数组中的视图,或者每当其中一个已排列的子视图的隐藏属性发生更改时,堆栈视图都会自动更新其布局.

SWIFT 3:

// Appears to remove the first arranged view from the stack.
// The view is still inside the stack, it's just no longer visible, and no longer contributes to the layout.
let firstView = stackView.arrangedSubviews[0]
firstView.hidden = true
Run Code Online (Sandbox Code Playgroud)

SWIFT 4:

let firstView = stackView.arrangedSubviews[0]
firstView.isHidden = true
Run Code Online (Sandbox Code Playgroud)