我正在努力模仿内置相机应用程序的基本功能。到目前为止,我一直停留在“点击聚焦”功能上。
我有一个 UIView,当一个手指点击 UIView 时,我从中收集 UITouch 事件。调用以下方法,但相机对焦和曝光不变。
-(void)handleFocus:(UITouch*)touch
{
if( [camera lockForConfiguration:nil] )
{
CGPoint location = [touch locationInView:cameraView];
if( [camera isFocusPointOfInterestSupported] )
camera.focusPointOfInterest = location;
if( [camera isExposurePointOfInterestSupported] )
camera.exposurePointOfInterest = location;
[camera unlockForConfiguration];
[cameraView animFocus:location];
}
}
'camera' 是我的 AVCaptureDevice & 它不是零。有人可以告诉我哪里出错了吗?
欢迎提供线索和嘘声。
M.
最佳答案
这个片段可能对你有帮助...有一个由 apple 提供的 CamDemo float ,它允许你对焦,在点击时改变曝光,设置闪光灯,交换相机等等,它很好地模拟了相机应用程序,不确定是否你将能够找到它,因为它是 wwdc 的一部分,但如果你在评论中留下一些电子邮件地址,我可以通过电子邮件将示例代码发送给你...
- (void) focusAtPoint:(CGPoint)point
{
AVCaptureDevice *device = [[self videoInput] device];
if ([device isFocusPointOfInterestSupported] && [device isFocusModeSupported:AVCaptureFocusModeAutoFocus]) {
NSError *error;
if ([device lockForConfiguration:&error]) {
[device setFocusPointOfInterest:point];
[device setFocusMode:AVCaptureFocusModeAutoFocus];
[device unlockForConfiguration];
} else {
id delegate = [self delegate];
if ([delegate respondsToSelector:@selector(acquiringDeviceLockFailedWithError:)]) {
[delegate acquiringDeviceLockFailedWithError:error];
}
}
}
}
关于iphone - 模拟相机应用程序 'tap to focus',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3345972/