我正在构建此代码以供将来学习和娱乐。它应该打开相机并启用触摸焦点。它适用于后置摄像头,但当我将其翻转到前置摄像头时没有任何反应。我搜索了很多,但找不到任何代码修复该问题。任何人都可以一步一步地向我展示代码如何使触摸焦点也在前置摄像头视图中工作?
下面是焦点功能:
- (void) focus:(CGPoint) aPoint{
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
if([device isFocusPointOfInterestSupported] &&
[device isFocusModeSupported:AVCaptureFocusModeAutoFocus]) {
CGRect screenRect = [[UIScreen mainScreen] bounds];
double screenWidth = screenRect.size.width;
double screenHeight = screenRect.size.height;
double focus_x = aPoint.x/screenWidth;
double focus_y = aPoint.y/screenHeight;
if([device lockForConfiguration:nil]) {
if([self.delegate respondsToSelector:@selector(scanViewController:didTapToFocusOnPoint:)]) {
[self.delegate scanViewController:self didTapToFocusOnPoint:aPoint];
}
[device setFocusPointOfInterest:CGPointMake(focus_x,focus_y)];
[device setFocusMode:AVCaptureFocusModeAutoFocus];
if ([device isExposureModeSupported:AVCaptureExposureModeAutoExpose]){
[device setExposureMode:AVCaptureExposureModeAutoExpose];
}
[device unlockForConfiguration];
}
}
}
整个来源可以在这里找到:
https://gist.github.com/Alex04/6976945
更新
if ([device isExposurePointOfInterestSupported])
{
[device lockForConfiguration:&error];
[device setExposurePointOfInterest:aPoint];
if ([device isExposureModeSupported:AVCaptureExposureModeContinuousAutoExposure])
{
[device setExposureMode:AVCaptureExposureModeContinuousAutoExposure];
}
[device setWhiteBalanceMode:AVCaptureWhiteBalanceModeContinuousAutoWhiteBalance];
[device unlockForConfiguration];
}
答案 0 :(得分:0)
我不认为前置摄像头支持任何iPhone上的点按对焦。您可以通过查看AVCaptureDevice
的{{3}}属性来检查支持情况。
如果您想实施点按曝光,请检查设备的focusPointOfInterestSupported
属性。如果设备支持该功能,请设置exposurePointOfInterestSupported
属性以使用它。