您可以根据方向强制应用水平尺寸类。如果我正确理解了你的目标,这里是一个可能方法的演示(用Xcode 12.1/iOS 14.1测试):
struct DemoViewSizes: View {
@Environment(\.horizontalSizeClass) var horizontalSizeClass
@State private var orientation = UIDevice.current.orientation
var body: some View {
Text("root_view_here")
.onReceive(NotificationCenter.default.publisher(for: UIDevice.orientationDidChangeNotification)) { _ in
orientation = UIDevice.current.orientation
}
.environment(\.horizontalSizeClass, orientation == .portrait ? .compact : .regular)
}
}