So currently what I have been doing for determining what device type and orientation I am in for SwiftUI is using sizeClasses, usually something like the following:
struct SizeClassView: View {
@Environment(\.verticalSizeClass) var verticalSizeClass: UserInterfaceSizeClass?
@Environment(\.horizontalSizeClass) var horizontalSizeClass: UserInterfaceSizeClass?
var body: some View {
if horizontalSizeClass == .compact && verticalSizeClass == .regular {
Text("iPhone Portrait")
}
else if horizontalSizeClass == .regular && verticalSizeClass == .compact {
Text("iPhone Landscape")
}
else if horizontalSizeClass == .regular && verticalSizeClass == .regular {
Text("iPad Portrait/Landscape")
}
}
}
What I'd like to know is: Is there any better way to do this in SwiftUI? The main problem I'm having with this method is that I can't differentiate between iPad Portrait and Landscape, but at least I can use it to differentiate between iPhone Portrait and iPhone Landscape and iPad... Any help and insight is greatly appreciated!
Apple strongly discourages the use of "landscape" and "portrait" modes in applications and strongly encourages the use of size classes. That implies that your original method - above - is probably the correct way to go. However, size classes cannot tell you what device you are using.
When using multiple windows on iPad, those windows may have compact widths or heights. Therefore you cannot conclude from size classes that your device is an iPhone in the way that you have done in your original post.
(By the way. Thanks for the size classes code. It was just what I was looking for for my application.)
Regards,
Vince.