ios10: viewDidLoad frame width/height not initialized correctly

前端 未结 7 921
闹比i
闹比i 2020-12-07 20:23

Since upgrading to XCode8 GM and ios10, all of my views created via Interface Builder are not being initialized correctly until much much later than expected. This means in

相关标签:
7条回答
  • 2020-12-07 21:23

    You should never rely on the timing of when a view is layed out. If that worked for you before, then out of pure luck. There are very little guarantees about this in UIKit. If you rely on something adopting to the size of your view, the right thing to do is override layoutSubviews in that view and adjust your stuff there.

    Even after your view is fully rendered on screen, there are still so many conditions that could cause the size of the view to change. For example: Double height status bar, multitasking on iPad, device rotation, just to name a few. So it never is a good idea to do frame related layout changes at a particular point in time.

    0 讨论(0)
提交回复
热议问题