2012-11-14 68 views
3

我是新來的Objective C,這是我在這裏發佈的第一個問題,所以這可能是世界上最簡單的問題,但我無法確定一出。UIImagePickerController with cameraOverlayView在點擊疊加中的按鈕時會聚焦

我想創建一個使用相機的iOS應用程序。我使用UIImagePickerController類來顯示相機和拍照,但我創建了一個自定義UIView,其中包含一系列覆蓋相機預覽幀的UIButton實例,使用cameraOverlayView屬性。我使用的方法把相機屏幕上使用此代碼:

- (BOOL) startCameraControllerFromViewController: (UIImagePickerController*) imagePickerController 
           usingDelegate: (id <UIImagePickerControllerDelegate, 
               UINavigationControllerDelegate>) imagePickerControllerDelegate { 

if (([UIImagePickerController isSourceTypeAvailable: 
     UIImagePickerControllerSourceTypeCamera] == NO) 
    || (imagePickerController == nil) 
    || (imagePickerControllerDelegate == nil)) 
    return NO; 

imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera; 

imagePickerController.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeImage, nil]; 

imagePickerController.allowsEditing = NO; 
imagePickerController.showsCameraControls = NO; 
imagePickerController.wantsFullScreenLayout = YES; 

imagePickerController.delegate = imagePickerControllerDelegate; 

self.cameraOverlayViewController = [[CameraOverlayViewController alloc] initWithImagePickerControllerDelegate:imagePickerController nibName:@"CameraOverlayView" bundle:nil]; 
self.cameraOverlayViewController.view.frame = CGRectMake(0, 0, imagePickerController.view.frame.size.width, imagePickerController.view.frame.size.height); 
imagePickerController.cameraOverlayView = self.cameraOverlayViewController.view; 

[self presentViewController:imagePickerController animated:self.showCameraAnimation completion:^(void) { 
    [self.view bringSubviewToFront:self.cameraOverlayViewController.view]; 
}]; 

return YES; 

}

當我按下位於相機預覽窗口頂部的按鈕,相應的IBAction爲被觸發,但是底部的攝像機視圖也可以輕拍並重新聚焦。所以每次按下按鈕,我都必須手動重新調焦相機預覽才能拍攝照片。正如你可以看到我試圖使用bringSubViewToFront :,但那似乎不起作用。

當我點擊cameraOverlayView上的按鈕時,如何防止相機聚焦?

Thnx求助!

+0

這項工作? [imagePickerController.view bringSubviewToFront:self.cameraOverlayViewController.view]; – jithinroy

回答

0

添加到您的代碼:hitTest:withEvent:

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event { 
    UIView *hittedView = [super hitTest:point withEvent:event]; 
    return hittedView == self.button ? hittedView : nil; 
} 

我refered這樣: UserInteraction enable for subview only。我測試了代碼。它的工作原理!

+0

嗯,[imagePickerController.view setUserInteractionEnabled:NO]似乎沒有做任何事情。我仍然可以點擊重點。 – Nelis86

+0

我發現這個話題:http://iphonedevsdk.com/forum/iphone-sdk-development/76953-tap-to-focus-in-uiimagepickercontroller.html 它基本上說,你必須添加覆蓋視圖作爲子視圖到UIImagePickerController視圖。問題是,這會禁用輕擊焦點。我需要點擊重點,所以這不是我的正確解決方案,但也許別人可能會覺得這很有用。 – Nelis86

+0

再次嘗試我的答案。我認爲它會爲你工作。 – sunkehappy

相關問題