iOS equivalent for Android View.GONE visibility mode

前端 未结 13 779
臣服心动
臣服心动 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 19:52

    This question is pretty old but the closet thing I've found is setting additional constraints (so the views around the "gone" view know what to do once it's missing)

    A  which you want to be     A
    |  after setting B to gone  |
    B                           C
    |                               
    C                               
    
    1. Set a lower priority (750) constraint from C to A.
    2. Add B's top and bottom constraints (or left and right if you want your view to collapse horizontally) to an NSLayoutConstraint array bConstraints. Do this by:
      1. Control click and drag from the constraint to the ViewController
      2. Change Connection from Outlet to Outlet Collection
      3. For name put bConstraints.
      4. Hit connect. This will create an @IBOutlet var bConstraints: [NSLayoutConstraint]! in your ViewController
      5. To add additional constraints: drag from the constraint in Storyboard to the @IBOutlet variable name
    3. Then hide B

      B.hidden = true
      NSLayoutConstraint.deactivateConstraints(bConstraints)
      
    4. To unhide

      B.hidden = false
      NSLayoutConstraint.activateConstraints(bConstraints)
      

    Obviously the more and more views you have the more complex this grows, as you need additional constraints from each view

提交回复
热议问题