In iOS and iPadOS, size classes (compact and regular) control the layout behaviour of UI elements. We can get the old behaviour using TraitOverrides. This solves the issue.
self.traitOverrides.horizontalSizeClass = UIUserInterfaceSizeClass.compact