我正在iphone Xs Max上开发自定义相机。我的布局如下。唯一的UIView的顶部,左侧,右侧和底部边框固定在安全区域。但是,我看到的是我的视频捕获输出的顶部边框和安全视图的顶部边框之间的巨大空白。黑色空间是什么,我如何计算它的高度?
布局:
UIView约束:
码:
class NewCapturViewController: UIViewController, UIImagePickerControllerDelegate,AVCaptureVideoDataOutputSampleBufferDelegate {
var previewLayer = AVCaptureVideoPreviewLayer.init()
var captureSession: AVCaptureSession!
override func viewWillAppear(_ animated: Bool) {
startAVCaptureSession()
}
func startAVCaptureSession() {
print("START CAPTURE SESSION!!")
// Setting Up a Capture Session
self.captureSession = AVCaptureSession()
captureSession.beginConfiguration()
// Configure input
let videoDevice = AVCaptureDevice.default(for: .video)
guard
let videoDeviceInput = try? AVCaptureDeviceInput.init(device: videoDevice!) as AVCaptureInput,
self.captureSession.canAddInput(videoDeviceInput)else {return}
self.captureSession.addInput(videoDeviceInput)
// Capture video output
let videoOutput = AVCaptureVideoDataOutput.init()
guard self.captureSession.canAddOutput(videoOutput) else {return}
videoOutput.setSampleBufferDelegate(self, queue: DispatchQueue.init(label: "videoQueue"))
self.captureSession.addOutput(videoOutput)
// start
self.captureSession.commitConfiguration()
self.captureSession.startRunning()
// Display camera preview
self.previewLayer = AVCaptureVideoPreviewLayer.init(session: self.captureSession)
// Use 'insertSublayer' to enable button to be viewable
self.camViewOutlet.layer.insertSublayer(self.previewLayer, at: 0)
self.previewLayer.frame = self.camViewOutlet.frame
self.previewFrame = previewLayer.frame
print("previewLayer.frame: \(previewLayer.frame)")
}
}
最佳答案
这是因为您已将Align Top
设置为Safe Area
。请记住,此电话有一个缺口-因此安全区域会更低。
如果将Storyboard
中的电话更改为iPhone Xs
(如问题中所述),您将看到有这个间隙。您需要做的只是将top约束设置为Superview
而不是Safe Area
。
关于ios - iPhone Xs-使用AVCaptureVideoPreviewLayer时,为什么UIView的顶部边框和安全区域的顶部边框之间会有很大的间距?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53524775/