ios - 当 View Controller 被关闭时,补充 View 会短暂保留

标签 ios swift uiviewcontroller nslayoutconstraint jsqmessagesviewcontroller

我在 Collection View 的顶部添加了一个 View ,现在当我关闭 View 时,该 View 会保留一瞬间。有谁知道可能导致这种情况的原因吗?

let newView = UIView() newView.backgroundColor = UIColor.redColor() 

newView.translatesAutoresizingMaskIntoConstraints = false view.addSubview(newView) 

let pinTop = NSLayoutConstraint(item: newView, attribute: .Top, relatedBy: .Equal, toItem: 

self.topLayoutGuide, attribute: .Bottom, multiplier: 1.0, constant: 0) 

let heightConstraint = newView.heightAnchor.constraintEqualToAnchor(nil, constant: 50) 

let widthConstraint = NSLayoutConstraint(item: newView, attribute: .Width, relatedBy: .Equal, toItem: view, attribute: .Width, multiplier: 1.0, constant: 0) 

self.topContentAdditionalInset = 50 

NSLayoutConstraint.activateConstraints([pinTop, heightConstraint, widthConstraint])

enter image description here

enter image description here

enter image description here

最佳答案

如果您使用 viewController 关闭它,请尝试在 viewWillDissapear 中添加 newView .removeFromSuperview() 并在 viewWillAppear 中重新添加它

关于ios - 当 View Controller 被关闭时,补充 View 会短暂保留,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39323270/

相关文章:

ios - 如何不重用 UITableViewCell 并将单元格从 View 中消失后保留在内存中?

swift - 自定义 UITableViewCell 按钮调用不正确的目标

ios - 真的需要 bridgeToObjectiveC 吗?

ios - 以编程方式创建 UINavigationController 并将 UICollectionViewController 嵌入到容器中

ios - 如何从不同的 swift 文件访问一个类中的所有对象

ios - UIViewController viewDidLoad 在 init 方法完成之前调用

ios - 获取firebase服务器时间云函数

iphone - 在 SQLite 中获取表中填充行的总数

objective-c - 使用 ACAccountStore 时为 "(null) wants to access twitter"

ios - ios模拟器中的phonegap总是显示弹出窗口