2

I got a banner UIView which I want to remove if the user has NoAds Feature.

Problem is after I remove the banner UIView, I cant' find a way to set the constraints of the top view to wrap the rest of ViewController.

Here are some images for you to better understand.

StoryBoard, (Green Rectangle is the banner UIView. There's also another view above the banner UIView

The white space is when the UIView banner has been removed. I need to drag the above UIView to wrap the rest of the screen

I remove the banner UIView with removeFromSuperview() method.

On the storyboard, my bottom constraint is set to 0 towards the nearest neighbour which is the UIView banner at the time. Problem is, after I remove the Banner UIView, I want to set the bottom constraint of the above UIView to 0 towards the SuperView.

Thanks in advance.

AresProductions
  • 508
  • 1
  • 9
  • 23
  • 1
    try this `NSLayoutConstraint.deactivate(myView.constraints)` – a.masri May 13 '18 at 10:08
  • I can't seem to find a way how this could help me. I want the bottom constraint of the top UIView to change to 0 but not towards the banner UIView (which has been removed). I want it to become 0 towards the end of the SuperView. – AresProductions May 13 '18 at 10:17
  • 1
    Ok , you can try this sent fixed height constraint to `banner UIView` When you remove them set `myHeightConstraint.constant = 0 removeFromSuperview()` – a.masri May 13 '18 at 10:21

1 Answers1

2

Just you can use simple solution

you can set TopView , Banner in Vertical StackView with Distribution Fill alignment Fill

When one of Stack-view item Hidden then other will Expand

See Image

enter image description here

If you need To use Constrain you have activate and deactivate then call setNeedsLayout()

Abdelahad Darwish
  • 5,969
  • 1
  • 17
  • 35
  • 1
    This did it! Thank you, didn't even know about this option. :P – AresProductions May 13 '18 at 10:30
  • I have a static AdManager class that keeps an array of all the banner ads. Once the user purchases, I just remove all the banners from superview by looping the array. Since the banners were all in a stack view, it automatically works. – baskInEminence Jul 10 '20 at 02:26