Android App Development
iOS App Development
Flutter App Development
Cross Platform App Development
Hire on-demand project developers and turn your idea into working reality.
Big thanks to Webkul and his team for helping get Opencart 3.0.3.7 release ready!
Deniel Kerr
Founder. Opencart
Top Partners
In this article, we will read about the UIView Auto Layout Lifecycle.
We will discuss the steps a UIView undergoes before it is presented to a user.
So let’s start with the article.
Every UIView containing auto layout has 4 steps before presenting to the user.
We will discuss each step of the lifecycle assuming you have basic knowledge of the Auto layout.
One thing to remember is that the above-stated steps may or may not present sequentially in the lifecycle of the UIView with auto layout.
The initialization step initializes the UIView, after that other steps are present.
Calling updateConstraints() for each view manages the update step. This process happens automatically but sometimes we need to do this manually when we want to update the constraints after some event.
We use setNeedsUpdateConstraint() to invalidate the contraints.
After that, updateConstraintsIfNeeded() triggers updateConstraints() which updates the constraints.
Read what the official documentation says here.
We use layoutSubviews() when the constraints are not enough for the view layout.
Firstly, setNeedsLayout invalidates the view’s layout and then layoutIfNeeded() calls layoutSubviews() if the constraints are invalidated previously.
You must call the super.layoutSubviews() to layout the updated constraints, but try to avoid modifying the constraints outside the view.
Here is what Apple describes layoutSubview()
Displaying the pixels on the screen is the major target of the render step.
In this step, it is not necessary that any view has an auto layout or not.
This step uses drawRect to display the UIView content.
You should never call this method directly yourself. Firstly, invalidate that part of your view and then call setNeedsDisplay.
This is just an overview of the lifecycle of the UIView with auto layout.
You can go through the official documentation here to dig out more.
Please visit my other blogs here.
Thanks for your reading.
Your email address will not be published. Required fields are marked*
Name*
Email*
Save my name email and website in this browser for the next time I comment.
Be the first to comment.
We use cookies to personalize your experience. By continuing to visit this website you agree to our use of cookies. Learn more about privacy policy
Name
Email
Subject
Enquiry or Requirement
If you have more details or questions, you can reply to the received confirmation email.