我打开一个完整的模态视图
.fullScreenCover(isPresented: self.$isPresentedPlayerView){
NavigationLazyView((MainPlayerView(playerVM: PlayerVM(asset: self.mediaVM.asset), showModal: self.$isPresentedPlayerView)))
}
在 playerView .onApper 中,我使用以下代码强制屏幕进入横向模式:
func forceLandscapeLeftPlayerView(){
AppDelegate.orientationLock = UIInterfaceOrientationMask.landscape
UIDevice.current.setValue(UIInterfaceOrientation.landscapeLeft.rawValue, forKey: "orientation")
UINavigationController.attemptRotationToDeviceOrientation()
}
并且当它尝试关闭视图或将 isPresentedPlayerView 设置为 false 或通过 presentationMode.wrappedValue.dismiss() 屏幕未关闭时!任何想法???
这是关闭代码:
func closeView(){
DispatchQueue.main.async {
withAnimation{
self.playerVM.pause()
self.playerVM.destropyPlayer()
AppDelegate.orientationLock = UIInterfaceOrientationMask.portrait
UIDevice.current.setValue(UIInterfaceOrientation.portrait.rawValue, forKey: "orientation")
UINavigationController.attemptRotationToDeviceOrientation()
self.isPresentedPlayerView = false
}
}
}
顺便说一句,此代码适用于 Xcode 12.2 并停止适用于 xcode 12.3/ .4