【问题标题】:ios swift square photo viewfinderios swift方形照片取景器
【发布时间】:2017-11-29 16:18:48
【问题描述】:

我正在使用 Swift 4/iOS 11/Xcode 9.1 中的 AVFoundation 框架制作自定义相机视图控制器

我的 setUpCaptureSession 代码:(感谢 letsbuildthatapp.com 的 brian voong,我已按照他的 IG/firebase 教程进行操作,并广泛使用了他的工作!)

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 是我手动添加到情节提要的视图,纵横比为 1:1。我的问题在下面的屏幕截图中可见:

捕获会话确实在photoPreView.frame 内,但我希望捕获会话填满整个区域并放大,就像原生 iOS 相机的方形模式如何工作,或者 Instagram 的照片捕获如何出现一样。

【问题讨论】:

    标签: ios swift ios-camera


    【解决方案1】:

    在您的捕获层上,您应该设置...

    previewLayer.videoGravity = .resizeAspectFill
    

    【讨论】:

      猜你喜欢
      • 2016-09-04
      • 1970-01-01
      • 2015-05-16
      • 1970-01-01
      • 2012-03-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多