gpt4 book ai didi

swiftUI - 强制屏幕到横向后无法关闭模式屏幕

转载 作者:行者123 更新时间:2023-12-04 08:10:30 25 4
gpt4 key购买 nike

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

.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()
}
当它尝试关闭 View 或将 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

最佳答案

此代码有效。我删除了 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()
}
}




关于swiftUI - 强制屏幕到横向后无法关闭模式屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65990039/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com