ios - 使用Objective-C放大和缩小相机 View ?
<p><p>如何使用 UIPinchGestureRecognizer 和 AVCaptureDevice 应用放大和缩小相机 View 。
它没有正确缩放。<br/>
缩小在我的以下代码中不起作用:</p>
<pre><code> AVCaptureDevice *device =[AVCaptureDevice defaultDeviceWithMediaType:
AVMediaTypeVideo];
AVCaptureDeviceFormat *format = device.activeFormat;
CGFloat maxZoomFactor = format.videoMaxZoomFactor;
const CGFloat pinchVelocityDividerFactor = 2.0f;
if (pinchRecognizer.state == UIGestureRecognizerStateChanged || pinchRecognizer.state ==UIGestureRecognizerStateBegan)
{
NSError *error = nil;
if ()
{
CGFloat desiredZoomFactor = device.videoZoomFactor +
atan2f(pinchRecognizer.velocity, pinchVelocityDividerFactor);
// Check if desiredZoomFactor fits required range from 1.0
//to activeFormat.videoMaxZoomFactor
if((1.0 <= pinchRecognizer.scale) && (2.5 >= pinchRecognizer.scale))
device.videoZoomFactor = pinchRecognizer.scale * pinchRecognizer.scale;
;
}
else
{
NSLog(@"error: %@", error);
}
}
}
</code></pre>
<p>请帮助任何人。<br/>
谢谢</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>//捏手势识别器方法定义</p>
<pre><code>- (void)handlePinchZoom:(UIPinchGestureRecognizer *)pinchRecognizer
{
AVCaptureDevice *device =[AVCaptureDevicedefaultDeviceWithMediaType:
AVMediaTypeVideo];
AVCaptureDeviceFormat *format = device.activeFormat;
CGFloat maxZoomFactor = format.videoMaxZoomFactor;
NSArray *formats = device.formats;
const CGFloat pinchVelocityDividerFactor = 2.0f;
if (pinchRecognizer.state == UIGestureRecognizerStateChanged || pinchRecognizer.state ==UIGestureRecognizerStateBegan)
{
NSError *error = nil;
if ()
{
CGFloat desiredZoomFactor = device.videoZoomFactor +
atan2f(pinchRecognizer.velocity, pinchVelocityDividerFactor);
device.videoZoomFactor = MAX(1.0, MIN(desiredZoomFactor,
device.activeFormat.videoMaxZoomFactor));
;
}
else
{
NSLog(@"error: %@", error);
}
}
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - 使用Objective-C放大和缩小相机 View ?,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/35841390/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/35841390/
</a>
</p>
页:
[1]