模拟相机应用程序“点按焦点”

时间:2010-07-27 16:58:14

标签: iphone objective-c cocoa-touch avfoundation

我正在努力模仿内置相机应用的基本功能。到目前为止,我已经陷入“重点关注”功能。

我有一个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&这是非零的。有人可以告诉我哪里出错了吗?

线索&欢迎大家欢迎。

微米。

1 个答案:

答案 0 :(得分:27)

这个片段可能对你有所帮助......有一个苹果浮动提供的CamDemo允许你聚焦,点击时改变曝光,设置闪光灯,交换相机等等,它很好地模拟了相机应用程序,不确定是否你可以找到它,因为它是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];

            }

        }        

    }

}