iOS 10 Auto Layout - viewDidLayoutSubviews called repeatedly

962 Views Asked by At

The whole Storyboard is AutoLayout enabled.

When I put a log inside viewDidLayoutSubviews(), I can see it's called repeatedly, and never stops.

I don't have any auto layout red flags in the view controller.

What could be causing this? What would be the best way to debug this?...to find out which view is struggling?


UPDATE

It turned out to be a UILabel making this trouble. Even though it has all 4 constraints (x, y, width, height) It seem to be calling re layouts up the tree......

2

There are 2 best solutions below

1
On

If maybe you have some loops change the view property over and over again in some subviews. Check it and find it out. Stop it.

2
On

My best guess is that it would be related to how subviews are laid out in the storyboard. Maybe some erroneous wiring of the views. It's hard to help you out on this without some more context about how your views and view controllers are laid out. Do you have some code sample or storyboard that you could share?

You can try using the View Debugger tool in Xcode. I have not used this myself for debugging, besides just trying it out to see my view hierarchy. Start by putting a breakpoint the in the viewDidLayoutSubviews and observe how the hierarchy changes every time it's called.https://developer.apple.com/library/content/documentation/DeveloperTools/Conceptual/debugging_with_xcode/chapters/special_debugging_workflows.html