iOS Autolayout - Frame size not set in viewDidLayoutSubviews

后端 未结 2 998
北海茫月
北海茫月 2020-12-09 16:37

I\'m working on a keyboard for iOS 8 using Autolayout to place the buttons on the view.
When I\'m changing the layout using constraints, everything is appearing correctl

2条回答
  •  余生分开走
    2020-12-09 17:07

    Yes! I solved that problem myself.

    I'm not sure if I got it right, but that's what I think:

    • viewDidLayoutSubviews get's called every time when the layout is changing
    • viewDidLayoutSubviews get's called when the direct subviews of my view did layout, but the subviews of that subviews did not layout at that moment, so you can't get the size of them.

    My solution now was to manually call .layoutSubviews() on all my views which contains all my buttons of my keyboard. After that, I get the size of all the buttons I want.

    Please correct me if I'm wrong.

提交回复
热议问题