Skip to content

Commit

Permalink
Add warnings to constraint removal convenience methods
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
smileyborg committed Sep 24, 2013
1 parent 1a6b9f1 commit 58a5086
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
8 changes: 6 additions & 2 deletions Source/UIView+AutoLayout.h
Expand Up @@ -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;


Expand Down
12 changes: 10 additions & 2 deletions Source/UIView+AutoLayout.m
Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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
Expand All @@ -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.
Expand Down

0 comments on commit 58a5086

Please sign in to comment.