|
Used Auto Layout will certainly have encountered the situation obtaining less than the true frame, and most people can get through a simple search for a satisfactory solution: Before you want to get real about the call frame self.view.layoutIfNeeded () this is not a good method, but can be: carried out without additional frame computing needs.
We View Controller life cycle to analyze the problem:
viewDidLoad
viewWillAppear
viewWillLayoutSubviews
viewDidLayoutSubviews
viewDidAppear
viewWillDisappear
viewDidDisappear
Auto Layout layout is from outside to inside, from the beginning of the layout of the screen size, the layout has been to the innermost details of the elements, our eyes naturally fall on the viewDidLayoutSubviews and viewDidAppear:
viewDidLayoutSubviews the current view of the handle element has layout is completed, frame has been formed
viewDidAppear, the rendering system added to the current view of the parent view, displayed on the screen
Therefore, the solution is already get to the bottom:
Avoid calling layoutSubviews, conducted in frame acquisition and viewDidAppear in viewDidLayoutSubviews
If you need to do some big action as soon as possible, it is recommended viewDidLayoutSubviews, then the user has not seen the UI, more flexible usage
Note viewDidLayoutSubviews may be called multiple times, so the added element of the class action to avoid doing here
viewDidAppear can dry everything you wanted to do things, but some require the user to see things like animation can do here
Recommended more needs to be done to try to put all the viewDidAppear do, allowing users to see the screen as soon as possible, which is the basic principle of human-computer interaction
Back to the question in the title: when to get in the right frame viewDidLayoutSubviews and viewDidAppear in?. |
|
|
|