iOS 13 - viewDidLayoutSubviews called on changing frame

958 Views Asked by At

There is some change done in viewdidlayoutsubviews in iOS 13 that is causing it to be called later in the life cycle of the View Controller once it has finished its first callings (on changing frame). This is creating some weird effects in the apps.

What I have observed is that before iOS13 changing frames do not call viewdidlayoutsubviews while in new iOS 13 it gets called.

Is this some kind of new feature by Apple or some bug? Any suggestions on how to stop this behavior?

2

There are 2 best solutions below

1
charlyatwork On

I'm facing that issue only for an UIViewController which will be added as a child of a Container View Controller. The device was not rotated - these are just the methods which will be called if the UIViewController was initial added to the hierarchy:

iOS 12:

  1. viewDidLayoutSubviews
  2. viewDidAppear

iOS 13:

  1. viewDidAppear
  2. viewDidLayoutSubviews

For me, that's not a feature hence it does not make sense calling viewDidLayoutSubviews after viewDidAppear (if the device was not rotated). Looks like a bug on iOS 13.

0
Sherwin Zadeh On

I don't know if this is the same situation but for me viewDidLayoutSubviews wasn't called at the right time until I added the following for subviews that care about resizing viewDidLoad:

override func viewDidLoad() {
    super.viewDidLoad()
    cropView.setNeedsLayout()
    cropView.layoutIfNeeded()
}