iosautolayoutsubview

Ignore autolayout constraints and then restore them


I need to completely ignore autolayout constraints on a subview. I have tried using translatesAutoresizingMaskIntoConstraints = YES as although posts have stated. This is great and allows me to set the frame of my object. What this doesn't do is ignore the auto layout constraints completely as the views I am setting translatesAutoresizingMaskIntoConstraints = YES on are still causing debugger output "will attempt to recover by breaking constraint .....". How do I make it so the constraints won't even be referenced but truly ignored until I want to bring them back. Is there a simple solution?


Solution

  • On iOS 8 and later you can deactivate the constraint by setting the active property to false. You can create a IBOutlet list so you don't have to reference all the constraints one by one and activate and deactivate them all at once.

    For backwards compatibility, you can remove them from the view and add them again later.