【发布时间】:2015-08-07 21:44:36
【问题描述】:
我正在构建此代码以供将来学习和娱乐。它应该打开相机并启用触摸焦点。它适用于后置摄像头,但当我将其翻转到前置摄像头时没有任何反应。我已经搜索了很多,但找不到任何解决该问题的代码。谁能用代码一步一步地告诉我如何使触摸焦点也可以在前置摄像头视图中工作?
下面是焦点功能:
- (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];
}
【问题讨论】:
标签: ios objective-c camera avfoundation