I have a UIViewController that I need to wrap and use as a SwiftUI view. I have implemented the methods needed to lock device orientation for that view controller. When I use the UIViewController in an UIKit context, the orientation could be locked.
class ContentViewController : UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = UIColor.red
}
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return .portrait
}
override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {
return .portrait
}
override var shouldAutorotate: Bool {
return false
}
}
When I wrap it as a SwiftUI view with UIViewControllerRepresentable, the orientation could not be locked. The
struct ContentWrappedView : UIViewControllerRepresentable {
func makeUIViewController(context: Context) -> ContentViewController {
return ContentViewController.init()
}
func updateUIViewController(_ uiViewController: ContentViewController, context: Context) {
}
}
Is this expected behavior? Is there a way around it? I'll be using it in a framework and so, implementing it with AppDelegate doesn't work for me. Thanks in advance.