swift - 旋转设备时如何平滑调整视频层大小 | 斯威夫特 5
问题描述
目前我有以下功能用于播放和调整视频层的大小 - 旋转设备时 - 帧的大小不能平滑地调整到新位置。
func playVideo() {
guard let path = Bundle.main.path(forResource: "video", ofType: "mp4") else {
return
}
let asset: AVAsset = AVAsset(url: URL(fileURLWithPath: path))
let playerItem = AVPlayerItem(asset: asset)
let queuePlayer = AVQueuePlayer(playerItem: playerItem)
self.playerLooper = AVPlayerLooper(player: queuePlayer, templateItem: playerItem)
let playerLayer = AVPlayerLayer(player: queuePlayer)
playerLayer.frame = self.view.bounds
playerLayer.videoGravity = .resizeAspectFill
self.videoLayer.layer.addSublayer(playerLayer)
queuePlayer.play()
videoLayer.bringSubviewToFront(img)
videoLayer.bringSubviewToFront(signIn)
videoLayer.bringSubviewToFront(stack)
}
以下是我目前正在尝试调整的内容 - 可行但不流畅,视频停止播放几秒钟:
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransition(to: size, with: coordinator)
coordinator.animate(alongsideTransition: { (context) in
}) { (context) in
self.playVideo()
}
}
解决方案
推荐阅读
- java - Firebase 日志不起作用,并且在 firebase 上看不到日志
- php - 为什么我的电报机器人“callback_query”不起作用?
- google-app-engine - app.yaml 在 App Engine 上部署静态网站时出现问题,图像不会显示
- visual-studio-code - 选择要附加到的进程
- pytorch - Pytorch - building from source - CMAKE_BUILD_WITH_INSTALL_RPATH
- r - 如何从 R DBI 读取 SQL Server 中的转义表?
- c# - 如何编写任务包装器类型?(异步方法的返回类型必须是类任务类型)
- javascript - 是否可以整理 React useEffects?
- python - Python 的多处理 SharedMemory 以内存损坏告终
- rdf - SHACL 等效于 JSON 模式“uniqueItems”