首页 > 解决方案 > Reset Constraints for the other components after removing a UIView

问题描述

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.

标签: swiftxcodeuiviewcontrollerbanner-adssafearealayoutguide

解决方案


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()


推荐阅读