我有一个相机应用程序,允许用户拍照和录制视频。 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'。我试图解决这个问题,但我试图解决这个问题的努力并没有实现。
答案 0 :(得分:2)
想出来:将有问题的一行改为:
previewLayer?.setAffineTransform(CGAffineTransform(scaleX: scale, y: scale))