AutoLayout: UIView in UIView has the wrong frame

I work with AutoLayout in a storyboard, and everything seemed to be all right. However, when I put one UIView into another and apply all the restrictions that I want to use for both the container and its children, I noticed that the frame is incorrect in viewDidLayoutSubviews:. Instead of being a frame, I would expect it to be calculated taking into account my limitations, this is some disgustingly large frame (albeit in the right origin). For example, instead of the frame {{26, 10}, {444, 10}}, I get something like {{0, 0}, {320, 568}}.

Oddly enough, this only happens with a child UIView when I place it in another UIView, which has some limitations that apply to it with respect to its supervisor (which is a view controller view). Since I have the impression that I can expect my views to be set out correctly in accordance with my limitations in the method viewDidLayoutSubviews:, I am confused why this is happening.

Am I making any wrong assumptions? I would appreciate it if someone would help me point me in the right direction. Thank!

Note. This problem is completely resolved if I perform a setup that depends on the correct frame in viewDidAppear:, but this is a somewhat unsatisfactory workaround for me.

+4
source share
1 answer

Changes to automatic layout within borders do not necessarily end in -viewDidLayoutSubviews. How to put in the "Advance Auto Layout Toolbox" :

Constrained construction is an iterative process. Skipping a layout can make changes to constraints based on a previous layout solution, which again starts updating constraints after another layout goes over.

Documentation for -viewDidLayoutSubviews notes with an emphasis in the original :

However, this method, which is called, does not indicate that individual layouts of the view representations have been adjusted.

, ​​ subviews , ViewController , -viewWillLayoutSubviews .

, " ", .

  • -viewWillAppear. , -viewDidAppear, , , , , , . , -isMovingToParentViewController , .
  • -layoutIfNeeded , , . , , , . , Auto Layout, .

, , - . Auto Layout . .

+16

All Articles