I've tried this but it seems not to work.
override open var traitCollection: UITraitCollection {
if UIDevice.current.userInterfaceIdiom == .pad {
if #available(iOS 17.0, *) {
self.traitOverrides.horizontalSizeClass = .compact
} else {
return UITraitCollection(horizontalSizeClass: .compact)
}
}
return super.traitCollection
}
However this works. Unfortunately this method is deprecated starting iOS 17.
if UIDevice.current.userInterfaceIdiom == .phone {
if #available(iOS 17.0, *) {
return UITraitCollection(traitsFrom: [super.traitCollection, UITraitCollection(horizontalSizeClass: .compact)])
} else {
return UITraitCollection(horizontalSizeClass: .compact)
}
}
Still looking for a better solution.