我正在呈现一个模态SwiftUI视图:
let vc = UIHostingController(rootView: MaModalView(title: "TEST"))
vc.modalPresentationStyle = .fullScreen
present(vc, animated: true)
我不希望这个模式旋转,我希望它只在纵向模式下工作。
我如何得到一个SwiftUI视图只支持一个给定的方向?
只需重写支持的界面方向,如
let vc = MyViewController(rootView: MaModalView(title: "TEST"))
vc.modalPresentationStyle = .fullScreen
present(vc, animated: true)
class MyViewController: UIHostingController<MaModalView> {
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return .portrait
}
}