iOS equivalent for Android View.GONE visibility mode

前端 未结 13 753
臣服心动
臣服心动 2020-12-12 19:22

I\'m developing an app for iOS and I\'m using the Storyboard with AutoLayout ON. One of my view controllers has a set of 4 buttons, and in certain circumstances i would like

13条回答
  •  温柔的废话
    2020-12-12 20:00

    Building off the answer provided by Deniz, here is a solution using constraints in Swift

    For example: If you have 3 views, A_view B_view and C_view vertically aligned in that order and you want to "Hide" B and also adjust the difference, add a constraint

    B_view.removeFromSuperView()
    var constr = NSLayoutConstraint(item: C_view, 
                                    attribute: NSLayoutAttribute.Top, 
                                    relatedBy: NSLayoutRelation.Equal, 
                                    toItem: A_view, 
                                    attribute: NSLayoutAttribute.Bottom,
                                    multiplier: 1,
                                    constant: 20)
    view.addConstraint(constr)
    

    constant is (in this case) the amount of vertical space between C_view and A_view

提交回复
热议问题