[英]ios swift square photo viewfinder
I am making a custom camera view controller using AVFoundation frameworks in Swift 4/iOS 11/Xcode 9.1 我正在使用Swift 4 / iOS 11 / Xcode 9.1中的AVFoundation框架制作自定义相机视图控制器
My code for setUpCaptureSession: (credit to brian voong of letsbuildthatapp.com , I have followed his IG/firebase tutorial and made extensive use of his work!) 我对setUpCaptureSession代码:(信贷的Brian voong letsbuildthatapp.com ,我按照他的IG /火力教程,并大量使用他的工作!)
fileprivate func setupCaptureSession() {
let captureSession = AVCaptureSession()
//setup inputs
let captureDevice = AVCaptureDevice.default(for: AVMediaType.video)
do {
let input = try AVCaptureDeviceInput(device: captureDevice!)
if captureSession.canAddInput(input) {
captureSession.addInput(input)
}
} catch let err {
debugPrint(err)
}
//setup outputs
if captureSession.canAddOutput(output) {
captureSession.addOutput(output)
}
//setup output preview
let previewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
previewLayer.frame = photoPreView.frame
view.layer.addSublayer(previewLayer)
captureSession.startRunning()
}
photoPreView
is a view I manually added to the storyboard with aspect ratio 1:1. photoPreView
是我手动添加到故事板的视图,宽高比为1:1。 my issue is visible in this screenshot below: 我的问题在下面的截图中可见:
The capture session is indeed within photoPreView.frame
but I want the capture session to fill up the entire area and zoom in , much like how the square mode of the native iOS camera works, or how Instagram's photo capture appears as well. 捕获会话确实在
photoPreView.frame
但我希望捕获会话能够填满整个区域并放大,就像本机iOS相机的方形模式如何工作,或者Instagram的照片捕获方式一样。
在捕获图层上,您应该设置...
previewLayer.videoGravity = .resizeAspectFill
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.