i have used snapKit on DispatchQueue.main.async to set constraints programmatically. But i noticed that main.async sometimes causes freeze UI and i change method to use it. Now i have problem to use dynamic height, old method cause error when i try to make dynamic height depends of content...
OLD METHOD (innerView - is subview of view)
DispatchQueue.main.async {
view.snp.makeConstraints({ (make) in
make.top.equalToSuperview().inset(45)
make.left.right.equalToSuperview().inset(12)
make.bottom.equalTo(self.innerView.snp.bottom).offset(12)
})
}
//After i add it like superView.addSubView(view)
//superView contains view, and view(dynamic height) contains innerView
NEW METHOD
superView.addSubview(view)
view.snp.makeConstraints({ (make) in
make.top.equalToSuperview().inset(45)
make.left.right.equalToSuperview().inset(12)
make.bottom.equalTo(self.innerView.snp.bottom).offset(12)
})
I found issue, just in case someone will need it... add make.bottom.equalTo(self.innerView.snp.bottom).offset(12), after you add all superview constraints and it will work!