我想像使用AVCam的原生相机应用程序一样创建焦点功能,但无法创建相同的功能。我使用上面的代码:
if ([[[captureManager videoInput] device] isFocusPointOfInterestSupported]) {
CGPoint tapPoint = [tgr locationInView:[self videoPreviewView]];
CGPoint convertedFocusPoint = [self convertToPointOfInterestFromViewCoordinates:tapPoint];
[self addLayoutsOfAutoFocus:tapPoint];
[USERDEFAULTS setValue:[NSString stringWithFormat:@"%f",convertedFocusPoint.x] forKey:x_value];
[USERDEFAULTS setValue:[NSString stringWithFormat:@"%f",convertedFocusPoint.y] forKey:y_value];
[USERDEFAULTS synchronize];
[captureManager continuousFocusAtPoint:convertedFocusPoint];
[captureManager continuousExpousureAtPoint:convertedFocusPoint];
}
我正在尝试保存焦点,但下次重新加载相机时焦点会丢失。
请帮忙。
答案 0 :(得分:1)
我找到了解决方法。我发布在这里以供将来参考。我使用的技巧是再次使用用户点击的新点设置会话。这是代码;
- (void)tapToContinouslyAutoFocus:(UIGestureRecognizer *)tgr
{
if ([[[captureManager videoInput] device] isFocusPointOfInterestSupported]) {
CGPoint tapPoint = [tgr locationInView:[self videoPreviewView]];
CGPoint convertedFocus = [self convertToPointOfInterestFromViewCoordinates:tapPoint];
CGPoint convertedFocusPoint=CGPointMake(convertedFocus.y, convertedFocus.x);
[self addLayoutsOfAutoFocus:tapPoint];
[USERDEFAULTS setValue:[NSString stringWithFormat:@"%f",convertedFocusPoint.x] forKey:x_value];
[USERDEFAULTS setValue:[NSString stringWithFormat:@"%f",convertedFocusPoint.y] forKey:y_value];
[USERDEFAULTS synchronize];
[[self captureManager] setSession:nil];
[[self captureManager] setupSession];
[captureManager autoFocusAtPoint:convertedFocusPoint];
[captureManager autoExposureAtPoint:convertedFocusPoint];
}
}
当用户双击屏幕以进行对焦时,将调用上述方法。