New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add View Hierarchy Traversal to Remove Constraints #4
Conversation
Added a test to specify behavior when the constraint passed to removeConstraintsFromApplicableSuperview: applies only to subviews, not to the receiver itself or any of its superviews.
…onstraint applies to that superview.
Hi Robert, thanks a lot for your contribution.
Thanks, Florian On 02.07.2013, at 00:23, Robert Gilliam notifications@github.com wrote:
|
Both good points! Say there are two views, with A the superview of B. A holds some constraints that apply to B. I had assumed that the constraints affecting B would not automatically be removed from A when removing B from the view hierarchy. Some experimentation shows that this is not the case and they are automatically removed. Turns out I don't need this in my case! Thanks; it's always nice to delete some code. And thanks for the tip re: the containment API. I found out I was using it wrong shortly before seeing your post. I'll correct it above as to not mislead anyone who happens to read it. Enjoy your travels! |
removeConstraintsFromApplicableSuperview:
Added
removeConstraintsFromApplicableSuperview:
, which traverses through all the superviews of the receiver to remove each passed constraint from the nearest superview that holds it. This means that you can remain blissfully unaware of which superview FLKAutoLayout is adding constraints to when constraining a view, yet still remove them by calling it on either of the views that you used to configure the constraints.I discovered the need for this method when implementing a container view controller. When that container switches the single contained view controller it holds, I wanted to remove all constraints it configured on the previously contained view controller's view before removing it from the view hierarchy. In this case, I use it as follows:
When setting constraints on the activeViewController in
updateViewConstraints
, I populate the array of activeViewControllerPositioningConstraints.Unit Tests
I also took the opportunity to add a unit test target and wrote some tests to drive out the implementation of
removeConstraintsFromApplicableSuperview:
. Hopefully this will encourage others to improve the test coverage going forward.Repo Structure
And, as part of adding the unit test target, I messed with the repository directory structure a bit (hopefully for the better). I hope I'm not stepping on your toes too much here. Please do let me know your thoughts on both the organizational changes I made and the more substantial ones.