Swift 初学者。我的视频没有填满它的框架。这是我的代码。我需要实现什么才能让它占用我在 Storyboard 中设置的空间?
导入UIKit 导入AVFoundation 导入AVKit
ViewController 类:UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
扩展 ViewController:UITableViewDelegate、UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cellview", for: indexPath) as! DataCellClass
let videourl = URL(fileURLWithPath: Bundle.main.path(forResource: "sample", ofType: "mp4")!)
let avPlayer = AVPlayer(url: videourl as URL)
cell.PlayerView?.playerLayer.player = avPlayer
cell.PlayerView.player?.play()
return cell
}
}
最佳答案
尝试在 Storyboard 的 DataCellClass 中查看 AVPlayer 的内容模式。确保将其设置为宽高比填充
这可能会有所帮助。 https://useyourloaf.com/blog/stretching-redrawing-and-positioning-with-contentmode/
关于swift - 如何使用 AVFoundation 制作视频填充框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50027344/