我打开一个完整的模式视图
.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() screen not close!有什么想法吗?
下面是闭合代码:
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
}
}
}顺便说一句,这段代码在Xcode12.2上工作,在Xcode12.3上停止工作/ .4
发布于 2021-02-01 18:01:52
这段代码可以工作。我删除了DispatchQueue、withAnimation和前三行。也许,问题出在别的地方。
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()
}
}https://stackoverflow.com/questions/65990039
复制相似问题