iOS equivalent for Android View.GONE visibility mode

前端 未结 13 745
臣服心动
臣服心动 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

    0 讨论(0)
  • 2020-12-12 19:54

    setHidden:TRUE/FALSE is the nearest equivalent to Android View.GONE/VISIBLE.

    The View not necessarily take space if not visible!

    I have made a ComboBox-Alike with a ListView laying on top of other views. I's only visible while selecting:

    enter image description here

    0 讨论(0)
  • 2020-12-12 19:55

    All of answers on this questions are inefficient. Best way to equvailent of Android setVisibility:Gone method on iOS is that StackView first select components then in editor, embed in, Stack View,

    connect new stack view with IBOutlet, then:

    hidden:

    UIView * firstView = self.svViewFontConfigure.arrangedSubviews[0];
            firstView.hidden = YES;
    

    visibility:

    UIView * firstView = self.svViewFontConfigure.arrangedSubviews[0];
            firstView.hidden = NO;
    

    as using stack view, all constraints will be keeped!

    Document

    0 讨论(0)
  • 2020-12-12 19:56

    https://github.com/tazihosniomar/LayoutManager

    i hope it will help you .

    0 讨论(0)
  • 2020-12-12 19:59

    Adding a constraint(NSLayoutAttributeHeight) that sets height of the view to 0 worked for me:

    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.captchaView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:0]];
    
    0 讨论(0)
  • 2020-12-12 19:59

    You can also clear the page, or at least certain cells of the page, and redefine the whole thing. It's fast and works well. I didn't write the code but found it in this pre-existing project I'm working on. Create ManagementTableSection and ManagementTableCell classes to manage it all. Sorry I can't provide better defined code.

    0 讨论(0)
提交回复
热议问题