swift - 删除 UIView 后重置其他组件的约束

标签 swift xcode uiviewcontroller banner-ads safearealayoutguide

我有一个横幅UIView,如果用户具有无广告功能,我想将其删除。

问题是在我删除横幅 UIView 后,我无法找到一种方法来设置顶 View 的约束来包裹 ViewController 的其余部分。

这里有一些图片可以让您更好地理解。

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

我使用 removeFromSuperview() 方法删除横幅 UIView

在 Storyboard上,我的底部约束设置为 0 朝向最近的邻居,即当时的 UIView 横幅。问题是,在删除 Banner UIView 后,我想将上述 UIView 的底部约束设置为 0 朝向 SuperView。

提前致谢。

最佳答案

只需使用简单的解决方案即可

您可以在垂直 StackView 中设置 TopView 、 Banner 和 Distribution Fill 对齐填充

当堆栈 View 项目之一隐藏时,其他项目将展开

查看图片

enter image description here

如果您需要使用约束,您需要激活停用,然后调用setNeedsLayout()

关于swift - 删除 UIView 后重置其他组件的约束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50314922/

相关文章:

ios - 如何获取/查看 iOS 应用程序的崩溃报告

iOS 应用内购买在生产环境中无声无息地失败

ios - 如何在iOS中获取正在运行的应用程序的名称

swift - 在 CALayer 上使用自定义 CIFilter 显示 CALayer 没有变化

ios - UIViewController 中的 UISearchBar

ios - Objective-C 方法' Controller :didChangeObject:atIndexPath:forChangeType:newIndexPath

c++ - 在 Xcode 中链接 C++ 库(用于 Wt)

iphone - iOS 应用程序打开时刷新 View

ios - "loaded the "XXX "nib but the view outlet was not set."- 再次

ios - 防止 UITableViewCell ImageView 在点击时改变大小