【问题标题】:AVCapture and zooming of previewLayer in SwiftSwift 中 previewLayer 的 AVCapture 和缩放
【发布时间】:2016-11-16 19:47:54
【问题描述】:

我有一个相机应用程序,它允许用户拍照和录制视频。 iPhone 使用适配器连接到医用耳镜,因此捕获的视频非常小(大约一角硬币大小)。我需要能够缩放视频以填满屏幕,但不知道如何做到这一点。

我发现this answer here on SO 使用了 ObjC,但没有成功将其翻译成 Swift。我非常接近,但被卡住了。这是我处理 UIPinchGestureRecgoznier 的代码:

    @IBAction func handlePinchGesture(sender: UIPinchGestureRecognizer) {

    var initialVideoZoomFactor: CGFloat = 0.0

    if (sender.state == UIGestureRecognizerState.began) {
        initialVideoZoomFactor = (captureDevice?.videoZoomFactor)!
    } else {
        let scale: CGFloat = min(max(1, initialVideoZoomFactor * sender.scale), 4)

        CATransaction.begin()
        CATransaction.setAnimationDuration(0.01)
        previewLayer?.transform = CGAffineTransform(scaleX: scale, y: scale)
        CATransaction.commit()

        if ((captureDevice?.lockForConfiguration()) != nil) {
            captureDevice?.videoZoomFactor = scale
            captureDevice?.unlockForConfiguration()
        }

    }
}

这一行...

previewLayer?.transform = CGAffineTransform(scaleX: scale, y: scale)

... 给我错误“无法将类型“CGAffineTransform”的值分配给类型“CGTransform3D”。我正在尝试解决这个问题,但我试图解决这个问题的尝试没有结果。

【问题讨论】:

    标签: swift3 avfoundation avcapture xcode8.1


    【解决方案1】:

    想通了:将有问题的行更改为:

    previewLayer?.setAffineTransform(CGAffineTransform(scaleX: scale, y: scale))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-02-07
      • 2015-06-15
      • 2019-11-13
      • 2019-05-11
      • 1970-01-01
      • 2015-07-07
      • 2015-05-01
      相关资源
      最近更新 更多