1

I added a view to the top of my collection view, now when I dismiss the view remains for a split second. Does anyone have any idea to what might cause this?

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

slimboy
  • 1,633
  • 2
  • 22
  • 45

2 Answers2

1

If you are dismissing it with the viewController, try to add newView .removeFromSuperview() in viewWillDissapear and re-adding it in viewWillAppear

Tj3n
  • 9,837
  • 2
  • 24
  • 35
0

I was just missing a constraint, stupid me!

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