gpt4 book ai didi

swiftui - VideoPlayer View 可防止 SwiftUI 导航栏隐藏

转载 作者:行者123 更新时间:2023-12-04 15:01:05 25 4
gpt4 key购买 nike

当我放 VideoPlayer 时出现问题查看内部 NavigationView的父 View 或 subview 。在这个例子中, subview 将显示导航栏:

struct ParentView: View {
var body: some View {
NavigationView {
VStack {
Text("Parent View")

NavigationLink(destination: ChildView().navigationBarHidden(true)) {
Text("Child View")
}
}
.navigationBarHidden(true)
}
}
}

struct ChildView: View {
var body: some View {
VStack {
Text("Child View")
VideoPlayer(player: AVPlayer())
}
}
}

最佳答案

我遇到了同样的问题。不确定是什么原因造成的,但我最终更换了 VideoPlayer用一个自定义的。这消除了顶部的空间。

  struct CustomPlayer: UIViewControllerRepresentable {
let src: String

func makeUIViewController(context: UIViewControllerRepresentableContext<CustomPlayer>) -> AVPlayerViewController {
let controller = AVPlayerViewController()
let player = AVPlayer(url: URL(string: src)!)
controller.player = player
player.play()
return controller
}

func updateUIViewController(_ uiViewController: AVPlayerViewController, context: UIViewControllerRepresentableContext<CustomPlayer>) { }
}
在您想使用它的地方,请执行以下操作:
CustomPlayer(src: "<the source to the video>")

关于swiftui - VideoPlayer View 可防止 SwiftUI 导航栏隐藏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66897332/

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