gpt4 book ai didi

ios - UIPinchGestureRecognizer 缩放 AVCaptureConnection;不按比例缩小

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:38:56 26 4
gpt4 key购买 nike

我有一个问题,我有一个 UIPinchGestureRecognizer,我用它来缩放我的相机预览和相应的 AVCaptureConnection 进出。第一次放大和缩小没有问题,直到完成捏合缩放后松开手指。如果我尝试向内捏(缩放回正常的 1.0 比例),手势不会重置预览和 AVCaptureConnection 比例降低,因此预览和 AVCaptureConnection 保持相同的大小。

我该如何解决这个问题? if 语句确保比例不会低于 1.0,因为我们不允许将 AVCaptureConnection 的比例设置为低于 1.0。

- (void)zoomPreview:(UIPinchGestureRecognizer *)recognizer
{
CGFloat scale = recognizer.scale;

NSLog(@"Scale: %f",scale);

if (scale >= 1.0)
{
[[self.stillImageOutput.connections objectAtIndex:0] setVideoScaleAndCropFactor:scale];

self.previewView.transform = CGAffineTransformMakeScale(scale, scale);
}
}

最佳答案

通过反复试验解决了自己:

@property (nonatomic, assign) CGFloat lastScale;
@property (nonatomic, assign) CGFloat currentScale;

- (void)zoomPreview:(UIPinchGestureRecognizer *)recognizer
{
self.currentScale += recognizer.scale - self.lastScale;
self.lastScale = recognizer.scale;

if (recognizer.state == UIGestureRecognizerStateEnded || recognizer.state == UIGestureRecognizerStateCancelled)
{
self.lastScale = 1.0;
}

if (self.currentScale < 1.0)
{
self.currentScale = 1.0;
}

if (self.currentScale > 5.0)
{
self.currentScale = 5.0;
}

if (self.currentScale >= 1.0 && self.currentScale <= 5.0)
{
[[self.stillImageOutput.connections objectAtIndex:0]setVideoScaleAndCropFactor:self.currentScale];

self.previewView.transform = CGAffineTransformMakeScale(self.currentScale, self.currentScale);
}
}

关于ios - UIPinchGestureRecognizer 缩放 AVCaptureConnection;不按比例缩小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24708449/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com