I was wondering if it's possible to access the leading anchor and the trailing anchor of the AVPlayerLayer especially when the videoGravity property is set to resizeAspect. (I added an image and used red text to indicate where it is).
Currently, I'm working on a video camera app, and the view file, LiveCameraView, has one UIView, videoView, and the videoView is pinned to the LiveCameraView's safe area (only the leading and trailing).
I want to set the videoGravity as .resizeAspect, but I also want to pin the translucent black area's trailing (on the right side of the view which covers red and white record button) to the right-side edge of where the image is captured.
Sorry, it's hard to explain, but when I set the value to .resizeAspectFill, the whole width of the translucent black areas appeared. I want that happens when I use resizeAspect as well. So the right side of the LiveCameraView should display
- the full width of the translucent black area
- the black area since using resizeAspect
- Blue background area
So, I want to make sure somehow get the leading and the trailing of the AVPlayerLayer without the complete black area.
The HKView is a library I'm using and it's super class is UIView.
import AVFoundation
lazy var videoView: HKView = {
let view = HKView()
view.videoGravity = .resizeAspect
return view
}()
lazy var rightContainerView: UIView = {
let view = UIView()
view.backgroundColor = UIColor.translucentBlack()
return view
}()
required override init(frame: CGRect) {
super.init(frame: frame)
setupViews()
setupConstraints()
self.backgroundColor = .blue // put this for testing
}
func setupViews() {
self.addSubview(videoView)
hkView.addSubview(rightContainerView)
rightContainerView.addSubview(recordButton)
}
func setupConstraints() {
caneraView.anchor(top: self.topAnchor, leading: self.safeAreaLayoutGuide.leadingAnchor, bottom: self.bottomAnchor, trailing: self.safeAreaLayoutGuide.trailingAnchor)
rightContainerView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
rightContainerView.topAnchor.constraint(equalTo: cameraView.topAnchor),
rightContainerView.bottomAnchor.constraint(equalTo: cameraView.bottomAnchor),
rightContainerView.trailingAnchor.constraint(equalTo: cameraView.trailingAnchor),
rightContainerView.widthAnchor.constraint(equalTo: cameraView.widthAnchor, multiplier: 0.15)
])
}
