swiftUI-can';t强制屏幕切换至横向后关闭模式屏幕

swiftUI-can';t强制屏幕切换至横向后关闭模式屏幕,swiftui,ios14,xcode12,swiftui-navigationview,Swiftui,Ios14,Xcode12,Swiftui Navigationview,我打开一个完整的模态视图 .fullScreenCover(isPresented: self.$isPresentedPlayerView){ NavigationLazyView((MainPlayerView(playerVM: PlayerVM(asset: self.mediaVM.asset), showModal: self.$isPresentedPlayerView))) } 在playerView.onApper中,我强制屏幕进入横向模式 使用此代码: fu

我打开一个完整的模态视图

.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.Disclease()进行设置 屏幕未关闭! 有什么想法吗

这是关闭代码:

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上停止工作。我删除了
DispatchQueue
、带有动画的
和前三行。也许,问题出在其他地方

struct MainPlayerView: View {
    @Environment(\.presentationMode) var presentationMode
    
    
    var body: some View {
        NavigationView {
            Button(action: {
                self.resetOrientation()
                presentationMode.wrappedValue.dismiss()
            }, label: {
                Text("Click")
            })
        }
        .onAppear(perform: {
            UIDevice.current.setValue(UIInterfaceOrientation.landscapeLeft.rawValue, forKey: "orientation")
            UINavigationController.attemptRotationToDeviceOrientation()
        })
    }
    
    func resetOrientation() {
        UIDevice.current.setValue(UIInterfaceOrientation.portrait.rawValue, forKey: "orientation")
        UINavigationController.attemptRotationToDeviceOrientation()
    }
}





删除withAnimation中的前三行,看看是否有效。谢谢,有效!