SwiftUI - tvOS 上的 AVPlayerViewController 全屏
Posted
技术标签:
【中文标题】SwiftUI - tvOS 上的 AVPlayerViewController 全屏【英文标题】:SwiftUI - AVPlayerViewController Full Screen on tvOS 【发布时间】:2020-04-12 07:00:10 【问题描述】:我可以通过 SwiftUI 呈现 AVPlayerViewController
,但视频周围有一些填充,我希望它是全屏的。
在 SwiftUI 部分有以下内容:
var body: some View
NavigationView
List
ForEach(topicsArray) topic in
Section(header: Text(topic.title))
ForEach(0..<topic.shows.count) index in
NavigationLink(destination: PlayerView(showID: topic.shows[index]))
ShowCell(showID: topic.shows[index])
.navigationBarTitle("")
.navigationBarHidden(true)
.listStyle(GroupedListStyle())
.padding()
.onAppear(perform: initialDataLoad)
从NavigationLink
调用的显示播放器的代码是:
struct PlayerView: UIViewControllerRepresentable
var showID:Int
func makeUIViewController(context: Context) -> AVPlayerViewController
let pv = PlayerViewController()
pv.showID = showID
return pv
func updateUIViewController(_ viewController: AVPlayerViewController, context: Context)
class PlayerViewController: AVPlayerViewController
var showID:Int!
didSet
setup()
private var videoLaunch:VideoLaunch!
private func setup()
videoLaunch = VideoLaunch(showID: showID,
season: nil,
episodeID: nil,
selectedIndex: IndexPath(row: 0, section: 0),
showType: .single,
dataStructure: topics as Any,
screenType: .live)
playVideo()
private func playVideo()
guard let videoURL = self.videoLaunch.getMediaURL() else print("Problem getting media URL");return
self.player = AVPlayer(url: videoURL)
self.videoGravity = .resizeAspectFill
self.player?.play()
我尝试设置边界并将modalpresentationstyle
用于全屏,但没有任何影响。视频周围仍然有一个看起来像 10 磅的边框。
【问题讨论】:
【参考方案1】:我能够通过在 PlayerViewController
类中插入以下内容来解决该问题。
override func viewDidLayoutSubviews()
self.view.bounds = UIScreen.main.bounds
【讨论】:
以上是关于SwiftUI - tvOS 上的 AVPlayerViewController 全屏的主要内容,如果未能解决你的问题,请参考以下文章
如何在 SwiftUI 中使 UIViewRepresentable 在 tvOS 上具有焦点?