下面我已经粘贴了缩放模块的代码。缩放也很有效,拍摄照片的结果图像不是根据缩放,结果图像稍微放大。有人可以指导我。谢谢
func pinchToZoom(sender:UIPinchGestureRecognizer){
if(sender.state == .Began){
scale = sender.scale
}
if(sender.state == .Began || sender.state == .Changed){
//NEW
var effectiveScale = scale * sender.scale
if(effectiveScale < 1.0){
effectiveScale = 1.0
}
let maxScale = self.imageOutput.connectionWithMediaType(AVMediaTypeVideo).videoMaxScaleAndCropFactor
if(effectiveScale > maxScale){
effectiveScale = maxScale
}
//Transform
CATransaction.begin()
CATransaction.setAnimationDuration(0.25)
let transform = CGAffineTransformMakeScale(effectiveScale, effectiveScale)
cameraView.transform = transform
CATransaction.commit()
scale = sender.scale // Store the previous scale factor for the next pinch gesture call
do {
try device.lockForConfiguration()
device.videoZoomFactor = effectiveScale
device.unlockForConfiguration()
} catch {
print(error)
}
}
}