From 58a508649c5e16cfd63a12ce863060b3affd14fd Mon Sep 17 00:00:00 2001 From: Tyler Fox Date: Tue, 24 Sep 2013 14:11:13 -0700 Subject: [PATCH] Add warnings to constraint removal convenience methods Per a direct conversation with Apple, using these methods to "nuke" all the constraints on a view or view hierarchy and then installing a fresh set of constraints will result in disastrous performance when the Auto Layout engine/solver attempts to recalculate the view frames. Instead, you'll want to make sure views are only reused with the same constraints (or with very small differences or changes to the constant value of the constraints). --- Source/UIView+AutoLayout.h | 8 ++++++-- Source/UIView+AutoLayout.m | 12 ++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Source/UIView+AutoLayout.h b/Source/UIView+AutoLayout.h index 72038d9..21f7a5c 100755 --- a/Source/UIView+AutoLayout.h +++ b/Source/UIView+AutoLayout.h @@ -60,19 +60,23 @@ typedef void(^ALConstraintsBlock)(void); // a block of method calls to the UI + (void)removeConstraints:(NSArray *)constraints; /** Removes all explicit constraints that affect the view. + WARNING: Apple's constraint solver is not optimized for large-scale constraint changes; you may encounter major performance issues after using this method. NOTE: This method preserves implicit constraints, such as intrinsic content size constraints, which you usually do not want to remove. */ - (void)removeConstraintsAffectingView; /** Removes all constraints that affect the view, optionally including implicit constraints. - WARNING: Implicit constraints are auto-generated lower priority constraints, and you usually do not want to remove these. */ + WARNING: Apple's constraint solver is not optimized for large-scale constraint changes; you may encounter major performance issues after using this method. + NOTE: Implicit constraints are auto-generated lower priority constraints, and you usually do not want to remove these. */ - (void)removeConstraintsAffectingViewIncludingImplicitConstraints:(BOOL)shouldRemoveImplicitConstraints; /** Recursively removes all explicit constraints that affect the view and its subviews. + WARNING: Apple's constraint solver is not optimized for large-scale constraint changes; you may encounter major performance issues after using this method. NOTE: This method preserves implicit constraints, such as intrinsic content size constraints, which you usually do not want to remove. */ - (void)removeConstraintsAffectingViewAndSubviews; /** Recursively removes all constraints from the view and its subviews, optionally including implicit constraints. - WARNING: Implicit constraints are auto-generated lower priority constraints, and you usually do not want to remove these. */ + WARNING: Apple's constraint solver is not optimized for large-scale constraint changes; you may encounter major performance issues after using this method. + NOTE: Implicit constraints are auto-generated lower priority constraints, and you usually do not want to remove these. */ - (void)removeConstraintsAffectingViewAndSubviewsIncludingImplicitConstraints:(BOOL)shouldRemoveImplicitConstraints; diff --git a/Source/UIView+AutoLayout.m b/Source/UIView+AutoLayout.m index 3e4f3dd..933f193 100755 --- a/Source/UIView+AutoLayout.m +++ b/Source/UIView+AutoLayout.m @@ -106,6 +106,8 @@ + (void)removeConstraints:(NSArray *)constraints /** Removes all explicit constraints that affect the view. + WARNING: Apple's constraint solver is not optimized for large-scale constraint changes; you may encounter major performance issues after using this method. + It is not recommended to use this method to "reset" a view for reuse in a different way with new constraints. Create a new view instead. NOTE: This method preserves implicit constraints, such as intrinsic content size constraints, which you usually do not want to remove. */ - (void)removeConstraintsAffectingView @@ -115,7 +117,9 @@ - (void)removeConstraintsAffectingView /** Removes all constraints that affect the view, optionally including implicit constraints. - WARNING: Implicit constraints are auto-generated lower priority constraints (such as those that attempt to keep a view at + WARNING: Apple's constraint solver is not optimized for large-scale constraint changes; you may encounter major performance issues after using this method. + It is not recommended to use this method to "reset" a view for reuse in a different way with new constraints. Create a new view instead. + NOTE: Implicit constraints are auto-generated lower priority constraints (such as those that attempt to keep a view at its intrinsic content size by hugging its content & resisting compression), and you usually do not want to remove these. @param shouldRemoveImplicitConstraints Whether implicit constraints should be removed or skipped. @@ -140,6 +144,8 @@ - (void)removeConstraintsAffectingViewIncludingImplicitConstraints:(BOOL)shouldR /** Recursively removes all explicit constraints that affect the view and its subviews. + WARNING: Apple's constraint solver is not optimized for large-scale constraint changes; you may encounter major performance issues after using this method. + It is not recommended to use this method to "reset" views for reuse in a different way with new constraints. Create a new view instead. NOTE: This method preserves implicit constraints, such as intrinsic content size constraints, which you usually do not want to remove. */ - (void)removeConstraintsAffectingViewAndSubviews @@ -149,7 +155,9 @@ - (void)removeConstraintsAffectingViewAndSubviews /** Recursively removes all constraints that affect the view and its subviews, optionally including implicit constraints. - WARNING: Implicit constraints are auto-generated lower priority constraints (such as those that attempt to keep a view at + WARNING: Apple's constraint solver is not optimized for large-scale constraint changes; you may encounter major performance issues after using this method. + It is not recommended to use this method to "reset" views for reuse in a different way with new constraints. Create a new view instead. + NOTE: Implicit constraints are auto-generated lower priority constraints (such as those that attempt to keep a view at its intrinsic content size by hugging its content & resisting compression), and you usually do not want to remove these. @param shouldRemoveImplicitConstraints Whether implicit constraints should be removed or skipped.