6

I have a problem where I want to modify NSLayoutconstraints on a UIView but it appears a lot of the properties are readonly. I initially have four UIViews as squares in a sort of quad view and they are all tied to each other with a gap of about 20 pixels.

I have a button that increases the frame of one of those squares into full screen encompassing all others. It is at this point I would like to change the constraints of that UIView to attach it to the superviews borders at 20 pixels, that way when I rotate it it doesn't go back to the quad view but maintains full screen. It looks like the property I would want to change is 'seconditem' but this won't work. Am I approaching this problem in the wrong way? I find Autolayout a bit difficult so any help would be much appreciated

0

1 Answer 1

9

Hi you can do 2 sets of constraints :

  • 1 to manage your quad view with priority High
  • 1 to manage your fullscreen with priority Low

In the method called when you tap your button, set priority high to your fullscreen constraints and priority low to your quad view constraints.

Sign up to request clarification or add additional context in comments.

5 Comments

That seems logical, I did get this runtime error though: Mutating a priority from required to not on an installed constraint (or vice-versa) is not supported. You passed priority 250 and the existing priority was 1000
Yes, the constraints you want to change priority need not to be "required" (priority = 1000). As I told you, set them to "high" (priority = 750) and switch to "low" (priority = 250), and conversely.
Thanks, gave it a go, but ended up messing other views up (probably due to badly designed constraints)! I ended up just saving and removing all the constraints when the button was pressed and creating a bunch of new ones programatically to get the desired effect. After finished I could just reverse the process.
I add two constraints for Height(one 0 heigh, another normal) for one view. looks like change their priority can't update the height, to get the hidden & un hidden effect
this is what happens when you are setting priority on constraint: *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Mutating a priority from required to not on an installed constraint (or vice-versa) is not supported. You passed priority 1 and the existing priority was 1000.'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.