我正在使用 webRTC 远程视频流并将远程会话附加到此:
@IBOutlet weak var remoteVideoElement: QBRTCRemoteVideoView!
我想要发生的是当用户点击上面的插座时,远程流会填满整个窗口。当用户再次点击它时,它将返回到它在布局中的正常位置。在大多数情况下,它工作正常,除了我无法保持远程视频流的正确纵横比或屏幕分辨率。有人可以帮我找出获得预期效果的正确方法吗?
这是我的代码:
var isExpanded = Bool()
var videoPlayerViewCenter = CGPoint()
override func viewDidLoad() {
super.viewDidLoad()
isExpanded = false
let toggleFullScreen = UITapGestureRecognizer(target: self, action: #selector (self.toggleFullScreenRemoteVideo(sender:)))
self.view.addGestureRecognizer(toggleFullScreen)
}
func toggleFullScreenRemoteVideo(sender: QBRTCRemoteVideoView) {
if !isExpanded {
// GO FULL SCREEN
UIView.animate(withDuration: 0.8, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: .curveEaseOut, animations: {
self.videoPlayerViewCenter = self.remoteVideoElement.center
self.view.bringSubview(toFront: self.modalShadeBackground)
self.view.bringSubview(toFront: self.remoteVideoElement)
self.remoteVideoElement.frame = CGRect(x: 0, y: 0, width: self.view.frame.height, height: self.view.frame.width)
self.remoteVideoElement.frame = AVMakeRect(aspectRatio: (self.remoteVideoElement.layer.preferredFrameSize()), insideRect: self.remoteVideoElement.frame)
self.remoteVideoElement.contentMode = .scaleAspectFit
self.remoteVideoElement.frame = UIScreen.main.bounds
self.remoteVideoElement.center = self.view.center
self.remoteVideoElement.transform = CGAffineTransform(rotationAngle: CGFloat(Double.pi / 2))
self.remoteVideoElement.layoutSubviews()
}, completion: nil)
} else {
// REVERT BACK TO ORIGINAL CONTRAINTS IN THE LAYOUT
UIView.animate(withDuration: 0.8, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: .curveEaseOut, animations: {
self.remoteVideoElement.transform = CGAffineTransform.identity
self.remoteVideoElement.center = self.videoPlayerViewCenter
self.view.sendSubview(toBack: self.remoteVideoElement)
self.view.sendSubview(toBack: self.modalShadeBackground)
self.remoteVideoElement.frame = AVMakeRect(aspectRatio: (self.remoteVideoElement.layer.preferredFrameSize()), insideRect: self.remoteVideoElement.frame)
self.remoteVideoElement.layoutSubviews()
}, completion: nil)
}
isExpanded = !isExpanded
}