【问题标题】:supplementary view remains briefly when viewcontroller is dismissed关闭视图控制器时,补充视图会短暂保留
【发布时间】:2016-09-05 02:45:20
【问题描述】:

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

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

【问题讨论】:

  • 你怎么解散它?
  • 使用 ios 的导航控制器后退按钮

标签: ios swift uiviewcontroller nslayoutconstraint jsqmessagesviewcontroller


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    我只是错过了一个约束,愚蠢的我!

            let centerX = NSLayoutConstraint(item: newView, attribute: NSLayoutAttribute.CenterX, relatedBy: NSLayoutRelation.Equal, toItem: self.view, attribute: NSLayoutAttribute.CenterX, multiplier: 1, constant: 0)
    

    【讨论】:

    • 所以你回答了自己的问题?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-01-23
    • 1970-01-01
    • 2017-01-06
    • 2018-03-08
    • 2014-09-10
    相关资源
    最近更新 更多