(GO) layoutSubviews summary and layoutsubviews Summary
I have never understood layoutSubviews very well. Let's take a look at this article:
LayoutSubviews Summary
Ios layout Mechanism
-(CGSize) sizeThatFits :( CGSize) size
-(Void) sizeToFit
-------
-(Void) layoutSubviews
-(Void) layoutIfNeeded
-(Void) setNeedsLayout
-------
-(Void) setNeedsDisplay
-(Void) drawRect
LayoutSubviews will be called in the following cases:
1. Initialization of init will not trigger layoutSubviews
However, when initWithFrame is used for initialization, when the rect value is not CGRectZero
2. addSubview triggers layoutSubviews
3. Setting the view Frame triggers layoutSubviews. Of course, the premise is that the frame value is changed before and after the Frame value is set.
4. Rolling a UIScrollView triggers layoutSubviews.
5. Rotating Screen triggers the layoutSubviews event on the parent UIView.
6. Changing the size of a UIView triggers the layoutSubviews event on the parent UIView.
In Apple's official documents, I emphasized:
You shoshould override this method only if the autoresizing behaviors of the subviews do not offer the behavior you want.
LayoutSubviews, which must be called when the position of the subview is adjusted within a class.
This means that if you want to set the location of the subviews externally, do not rewrite it.
Refresh sub-object Layout
-LayoutSubviews method: This method does not do anything by default and must be rewritten by subclass.
-SetNeedsLayout: The layoutIfNeeded method is called asynchronously to refresh the layout. If the layout is not refreshed immediately, layoutSubviews will be called.
-LayoutIfNeeded method: if there are tags to be refreshed, call layoutSubviews to layout immediately (if there is no tag, layoutSubviews will not be called)
If you want to refresh the page immediately, call [view setNeedsLayout], set the flag to layout, and call [view layoutIfNeeded] immediately to implement layout.
Before the view is displayed for the first time, you can directly call [view layoutIfNeeded]
Redraw
-DrawRect :( CGRect) rect method: rewrite this method to execute the re-painting task.
-SetNeedsDisplay method: mark it as re-painting required and call drawRect Asynchronously
-SetNeedsDisplayInRect :( CGRect) invalidRect method: Mark as partial repainting required
SizeToFit will automatically call the sizeThatFits method;
SizeToFit should not be overwritten in the subclass, and should be rewritten in sizeThatFits
The input parameter sizeThatFits is the current size of the aggreger, and an appropriate size is returned.
SizeToFit can be manually called directly
Neither the sizeToFit nor the sizeThatFits method is recursive, and it is not responsible for subviews. It is only responsible for itself.
------------
LayoutSubviews re-layout subviews
LayoutSubviews method call prior to drawRect
SetNeedsLayout indicates a tag that needs to be re-laid on the worker er. It automatically calls layoutSubviews in the next cycle of the system runloop.
If the layoutIfNeeded method is its name, UIKit will determine whether the handler requires layout. According to the official Apple documentation, the layoutIfNeeded method should be like this
LayoutIfNeeded does not traverse superview chains, but should be subviews chains.
DrawRect is a re-painting of the receiver, which can obtain the context
SetNeedDisplay indicates a tag to be re-drawn on the worker er. It is automatically re-painted in the next draw cycle. The refresh frequency of the iphone device is 60 hz, that is, re-painting after 1/60 seconds.
Http://www.cocoachina.com/bbs/read.php? Tid = 111832
Call when layoutsubviews
LayoutSubviews will be called in the following cases:
1. Initialization of init will not trigger layoutSubviews
2. addSubview triggers layoutSubviews
3. Setting the view Frame triggers layoutSubviews. Of course, the premise is that the frame value is changed before and after the Frame value is set.
4. Rolling a UIScrollView triggers layoutSubviews.
5. Rotating Screen triggers the layoutSubviews event on the parent UIView.
6. Changing the size of a UIView triggers the layoutSubviews event on the parent UIView.
Final work conclusion
Write it according to your actual situation. I mainly want to write about the main work content, how to work hard, how to make achievements, and finally propose new directions and positive requests .......
The work summary is to let your superiors know what contribution you have made and reflect the value of your work.
So we should write a few points:
1. Your understanding of your position and work 2. What have you done?
3. How do you work with your heart and what things are solved with your mind. Even if there is nothing, you have to write some difficult questions. How can you solve them through hard work?
4. What abilities or knowledge do you need to improve in your future work?
5. People who prefer to take the initiative to work at superiors. All your tasks should be prepared, that is, preparations in advance are as follows for your reference:
To sum up, we conduct a comprehensive and systematic overall evaluation and analysis of the situation within a period of time, and analyze the scores, deficiencies, and experiences. The conclusion is a kind of application writing and a rational reflection on the work that has already been done.
Summary of basic requirements
1. The summary must have an overview and description of the situation, some of which are relatively simple and some are relatively detailed.
2. Scores and shortcomings. This is the main content of the Summary. The purpose of the summary is to confirm the score and find out the shortcomings. What are the scores, what are the scores, what are the manifestations, and how they are achieved? What are the shortcomings, what are the manifestations, and how they are produced? Should be clearly written.
3. Experience and lessons learned. In order to facilitate future work, it is necessary to analyze, research, summarize previous work experiences and lessons, and form theoretical knowledge.
Note:
1. Be sure to seek truth from facts. The score is not exaggerated, and the shortcomings are not reduced. This is the basis for analysis and lessons learned.
2. The Organization should be clear. Statements are fluent and easy to understand.
3. Be specific and appropriate. There are important, secondary, and important points in writing. The problems in the summary should be classified into primary and secondary, and detailed points.
Basic summary format:
1. Title
2. Text
Start with: Overview, overall evaluation, outline and outline.
Subject: analyze the score defects and summarize lessons learned.
End: analyze the problem and clarify the direction.
3. Paid
Signature and date