I have a view which has dynamic height and I am trying to change this view height priority in run time.
Here is my part of code;
if (index == 0) {
I was facing the same issue. As some of the answer mentioned above in iOS 13 changing priority will work fine, However in iOS 12 it will lead to crash.
I was able to fix this problem by creating IBOutlet NSLayoutConstraint to that specific constraint in Storyboard retaining its priority to 1000, below is the code for fix.
if (Condition) {
surveyViewHeightConstraint.constant = 0;
surveyViewHeightConstraint.isActive = false;
} else if (index == 1) {
surveyViewHeightConstraint.constant = 163;
surveyViewHeightConstraint.isActive = True;
}
Hope this helps!!! Cheers
The way we have always handled this is by not changing the constraint constant, just the priority. For example, in your situation have two height constraints.
heightConstraintOne (who's height is set in the storyboard at 150, and priority set at 750)
heightConstraintTwo (who's height is set in the storyboard at 0, and priority set at 250)
if you want to hide the view, you:
heightConstraintTwo.priority = 999;
likewise, if you want to show the view:
heightConstraintTwo.priority = 250;