I'm having a problem with updating Constraints.
I add contraint by using this code.
var oldHeight = 92 + ((catAmount-10)*100)
self.mainViewport.addConstraint(NSLayoutConstraint(item: self.mainViewport, attribute: .Height, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: .NotAnAttribute, multiplier: 0, constant: CGFloat(oldHeight)))
This code works 100%, but when user scroll down i need to add more info to ViewController so I need to update constraints to. but I get ant error.
Unable to simultaneously satisfy constraints. Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) ( "", "" )
I've tried to remove constraint by this code:
self.mainViewport.removeConstraint(NSLayoutConstraint(item: self.mainViewport, attribute: .Height, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: .NotAnAttribute, multiplier: 0, constant: CGFloat(oldHeight)))
but it don't remove the old one so I can't add new or update constraint.
What I'm doing wrong? How I can update constraint continuously when i need?
P.S. I'm using ScrollViewController and a ViewController with info in it.
Code update.
class CategoryViewController: UIViewController, UIScrollViewDelegate {
var CategoriesConstraint : NSLayoutConstraint!
/** **/
var aukstis = 92 + (catAmount*100)
self.mainViewport.setTranslatesAutoresizingMaskIntoConstraints(false)
self.CategoriesConstraint = NSLayoutConstraint(item: self.mainViewport, attribute: .Height, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: .NotAnAttribute, multiplier: 0, constant: CGFloat(aukstis))
if(catAmount == 10){
self.mainViewport.addConstraint(self.CategoriesConstraint)
self.showApp(1,secondJson: 0)
} else {
self.CategoriesConstraint.constant = CGFloat(aukstis)
self.mainViewport.updateConstraints()
self.mainViewport.setNeedsLayout()
self.mainViewport.layoutIfNeeded()
}