这让我困扰了好几天...
在我的应用程序中,我使用 AVCapture 拍照,然后我使用 ZBar SDK 扫描条形码。问题是一旦我在拍照后加载 ZBar,我在拍摄另一张照片时就失去了自动对焦的能力。如果我先加载ZBar,那么我可以在拍照时调整焦点,但是ZBar失去了对焦的能力!我尝试将 ZBar 换成 ShopSavvy 代码扫描器 SDK,但我遇到了同样的问题......
这是我用来设置相机打开自动对焦但没有发生错误的代码,我无法对焦!
AVCaptureDevice *device = [[self videoInput] device];
if ([device isFocusPointOfInterestSupported] && [device isFocusModeSupported:AVCaptureFocusModeContinuousAutoFocus]) {
NSError *error;
if ([device lockForConfiguration:&error]) {
[device setFocusPointOfInterest:point];
[device setFocusMode:AVCaptureFocusModeContinuousAutoFocus];
[device unlockForConfiguration];
} else {
if ([[self delegate] respondsToSelector:@selector(captureManager:didFailWithError:)]) {
[[self delegate] captureManager:self didFailWithError:error];
}
}
}