我正在尝试在相机视图上实现缩放放大/缩小。
到目前为止我有这个代码:
- (void) setZoom:(float)zoomValue{
NSError *error = nil;
NSLog(@"Current zoom level %f " , zoomValue);
if([_device lockForConfiguration:&error]){
if(zoomValue > 1 ){
if(zoomValue < _device.activeFormat.videoMaxZoomFactor){
_device.videoZoomFactor = zoomValue;
[_device unlockForConfiguration];
}else{
_device.videoZoomFactor = _device.activeFormat.videoMaxZoomFactor;
//self.currentZoom = _device.activeFormat.videoMaxZoomFactor;
[_device unlockForConfiguration];
}
}else if(zoomValue < 1){
_device.videoZoomFactor = 1;
//self.currentZoom = 1;
[_device unlockForConfiguration];
}
}
}
这是捏手势处理程序的代码:
-(IBAction)handlePinchWithGestureRecognizer:(UIPinchGestureRecognizer *)pinchGestureRecognizer {
if ( pinchGestureRecognizer.state == UIGestureRecognizerStateBegan )
{
_zoomGestureCurrentZoom = pinchGestureRecognizer.scale;
}
else if ( pinchGestureRecognizer.state == UIGestureRecognizerStateChanged )
{
// we have to jump through some hoops to clamp the scale in a way that makes the UX intuitive
float scaleDeltaFactor = pinchGestureRecognizer.scale/_zoomGestureLastScale;
float currentZoom = self.zoomGestureCurrentZoom;
float newZoom = currentZoom * scaleDeltaFactor;
// clamp
float kMaxZoom = 6.0f;
float kMinZoom = 1.0f;
newZoom = MAX(kMinZoom,MIN(newZoom,kMaxZoom));
//self.view.transform = CGAffineTransformScale([[gestureRecognizer view] transform], newZoom, newZoom);
[_imageCameraSource setZoom:newZoom];
// store for next time
self.zoomGestureCurrentZoom = newZoom;
}
}
我遇到的问题很少:
如果有人有任何工作代码,最好看一看并弄清楚整个功能或欢迎任何其他建议。
由于