2

I open a full modal view

.fullScreenCover(isPresented: self.$isPresentedPlayerView){
     NavigationLazyView((MainPlayerView(playerVM: PlayerVM(asset: self.mediaVM.asset), showModal: self.$isPresentedPlayerView)))
}

and in playerView .onApper i force screen to Landscape mode with this code:

   func forceLandscapeLeftPlayerView(){
       AppDelegate.orientationLock = UIInterfaceOrientationMask.landscape
       UIDevice.current.setValue(UIInterfaceOrientation.landscapeLeft.rawValue, forKey: "orientation")
       UINavigationController.attemptRotationToDeviceOrientation()
   }

and when it try close view or by set isPresentedPlayerView to false or by presentationMode.wrappedValue.dismiss() screen not close! any idea???

this is close code:

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
        }
    }
}

BTW, this code work on Xcode 12.2 and stop work on xcode 12.3/ .4

israel_b_2012
  • 277
  • 1
  • 2
  • 8

1 Answers1

2

This code works. I removed DispatchQueue, withAnimation and the first three lines. Perhaps, the problem lies somewhere else.

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()
    }
}




mahan
  • 12,366
  • 5
  • 48
  • 83