StackView isHidden attribute not updating as expected

前端 未结 3 1409
生来不讨喜
生来不讨喜 2021-02-05 08:37

I\'m trying to update a UIStackView so that a field displays, should the value of a UITextField equal \"Other\". Here is my code:

3条回答
  •  醉话见心
    2021-02-05 09:11

    It's known UIStackView bug (http://www.openradar.me/25087688). There is a thread on SO about it: (Swift: Disappearing views from a stackView). Long story short:

    The bug is that hiding and showing views in a stack view is cumulative. Weird Apple bug. If you hide a view in a stack view twice, you need to show it twice to get it back.

    To fix this issue you can use following extension:

    extension UIView {
        var isHiddenInStackView: Bool {
            get {
                return isHidden
            }
            set {
                if isHidden != newValue {
                    isHidden = newValue
                }
            }
        }
    }
    

提交回复
热议问题