3

I am having a heck of a time with iOS 10 and autolayout stuff that used to work (similar to what others have posted regarding how late frames are set).

I have worked all of that out, but one problem lingers.

I have a pretty complex view, with one view inside another, with constraints on all 4 sides to match its superview. When everything is finished laying out, the superview has a Y of 141.5, and a height of 200 (exactly what it should be).

Unfortunately, the view inside it, which should have a Y of 0, has a Y of -141.5, and a height of 341.5. This means the interior view is too tall, and it is rendering on top of the views above it.

I have tried everything, including setting an explicit height constraint, but it's all ignored.

Why won't it stay where it belongs? This all worked perfectly in iOS 9.

Ken A
  • 83
  • 9
  • try forcing the layout by `[self.view layoutIfNeeded]` after setting the constraints http://stackoverflow.com/a/39548367/1045672 – Teffi Sep 27 '16 at 13:58
  • Actually, it turns out that you need to constrain the content of a scrollview's sides to the scrollview in iOS 10, which is the opposite of what would be intuitive to me. Once I started doing that, all was OK. Why would you need to do that? No idea. – Ken A Sep 28 '16 at 20:42
  • aren't you suppose to do that by default when supporting autolayout on scrollview? It's not iOS10 specific for what I know. – Teffi Sep 29 '16 at 02:08
  • Yes, that's what the doc says, but again, seems counter-intuitive to me, and it used to work without those constraints. To me, since the content of the scrollview is supposed to be bigger than the scrollview itself, how could you constrain all the edges? – Ken A Sep 30 '16 at 10:49

1 Answers1

0

While I can't say definitively why this is solved, it's fine now. What I did was move some view and constraint creation from viewDidLayoutSubviews to viewDidLoad (only once with a flag). Seems like the new version of the layout engine isn't happy with adding views and constraints that late in the game.

Ken A
  • 83
  • 9