override func viewDidLoad() {
super.viewDidLoad()
self.blurView = UIVisualEffectView(effect: UIBlurEffect(style: .ExtraLight)) as UIVisualEffectView
self.view.insertSubview(self.blurView, belowSubview: self.filterPanel)
self.blurView.addConstraint(NSLayoutConstraint(item: self.blurView, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: self.view, attribute: NSLayoutAttribute.Top, multiplier: 1, constant: 0))
self.blurView.addConstraint(NSLayoutConstraint(item: self.blurView, attribute: NSLayoutAttribute.Bottom, relatedBy: NSLayoutRelation.Equal, toItem: self.view, attribute: NSLayoutAttribute.Bottom, multiplier: 1, constant: 0))
self.blurView.addConstraint(NSLayoutConstraint(item: self.blurView, attribute: NSLayoutAttribute.Leading, relatedBy: NSLayoutRelation.Equal, toItem: self.view, attribute: NSLayoutAttribute.Leading, multiplier: 1, constant: 0))
self.blurView.addConstraint(NSLayoutConstraint(item: self.blurView, attribute: NSLayoutAttribute.Trailing, relatedBy: NSLayoutRelation.Equal, toItem: self.view, attribute: NSLayoutAttribute.Trailing, multiplier: 1, constant: 0))
}
When the above code is called, it crashes with the error "View hierarchy is not prepared for restriction." I can understand that this error occurs if I try to add a constraint before it is added to the view, but the view will be added, followed by the added constraints.
Any ideas?
source
share