[英]Non-modal UIImagePickerController, tap to focus doesn't work
我在非模態設置中使用UIImagePickerController,如下所示:
UIImagePickerController *_imagePickerVC = // init the VC with the main camera as the source
[_mainCameraPreviewContainer addSubview:_imagePickerVC.view];
[_mainCameraPreviewContainer bringSubviewToFront:_imagePickerVC.view];
這是有效的,我可以拍照,但我無法點擊預覽區域,使相機專注於該點。 我嘗試通過添加以下兩行中的一行或兩行來修復此問題:
_imagePickerVC.showsCameraControls = NO;
_imagePickerVC.view.userInteractionEnabled = YES;
但沒有運氣。 當我讓它顯示相機控件時,我確實得到了閃光模式按鈕和按鈕來選擇相機,但這些按鈕也不是可以點擊的。 是否有可能讓水龍頭專注於我的工作?
我重復你的代碼並點擊聚焦和按鈕工作。 (iOS 5.1,6.1)。
- (IBAction)buttonTap:(id)sender {
if (!_imagePickerVC)
{
_imagePickerVC = [UIImagePickerController new];
_imagePickerVC.sourceType = UIImagePickerControllerSourceTypeCamera;
}
[self.view addSubview:_imagePickerVC.view];
[self.view bringSubviewToFront:_imagePickerVC.view];
}
確保mainCameraPreviewContainer.userInteractionEnabled == YES
。
http://jcuz.wordpress.com/2010/02/17/pickerfocus/你可以嘗試一下。
我建議你使用AVfoundation實現。 它更容易,更靈活。 使用AVFoundation ios AVFoundation點擊聚焦
試試這個讓我知道..
_imagePickerVC.view.userInteractionEnabled = YES;
UIPanGestureRecognizer *pgr = [[UITapGestureRecognizer alloc]
initWithTarget:self action:@selector(handleTap:)];
[_imagePickerVC addGestureRecognizer:pgr];
[pgr release];
-(void)handleTap{
AVCaptureDevice *device = [[self captureInput] device];
NSError *error;
if ([device isFocusModeSupported:AVCaptureFocusModeAutoFocus] &&
[device isFocusPointOfInterestSupported])
{
if ([device lockForConfiguration:&error]) {
[device setFocusPointOfInterest:point];
CGPoint point = [touch locationInView:self.cameraView];
point.x /= self.cameraView.frame.size.width;
point.y /= self.cameraView.frame.size.height;
[self focusAtPoint:point];
[device unlockForConfiguration];
} else {
NSLog(@"Error: %@", error);
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.