gpt4 book ai didi

ios - iPhoneX : AVCaptureVideoPreviewLayer not occupying the entire screen?

转载 作者:行者123 更新时间:2023-11-30 10:59:46 26 4
gpt4 key购买 nike

我在 UIViewController 中制作了自定义相机,但无法在 iPhoneX 上的整个屏幕上预览相机输出。相机 View 和屏幕边缘之间似乎有很大的填充。我的视野似乎确实是从安全区域插入的。请问有人可以指教吗?

iPhoneXs Max: enter image description here

我的代码:

class CaptureImageViewController: UIViewController, UIImagePickerControllerDelegate, AVCaptureVideoDataOutputSampleBufferDelegate  {


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
previewLayer = AVCaptureVideoPreviewLayer.init(session: self.captureSession)

// Use 'insertSublayer' to enable button to be viewable
view.layer.insertSublayer(previewLayer, at: 0)
previewLayer.frame = view.frame
previewFrame = previewLayer.frame


}




}

我的布局:

enter image description here

enter image description here

最佳答案

尝试将 previewLayer.frame = view.frame 更改为

let frame = UIScreen.main.bounds
view.layer.insertSublayer(previewLayer, at: 0)
previewLayer.frame = frame
previewFrame = previewLayer.frame

关于ios - iPhoneX : AVCaptureVideoPreviewLayer not occupying the entire screen?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53516196/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com