2011-03-25 44 views
4

我有一個透明的視圖,使用CoreGraphics繪製一個矩形。 當相機啓動時,自定義疊加視圖位於快門動畫的上方。 你看到的是標準的相機快門,上面是自定義矩形。 如何讓它在正確的地方進入快門動畫下方?我已經看過其他示例代碼,但它是針對OS 3.1的,似乎沒有任何不同之處。cameraOverlayView上面快門動畫

這裏是我的代碼:

-(IBAction)cameraButton{ 
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerCameraDeviceRear]){ 

    UIImagePickerController *picker = [[UIImagePickerController alloc] init]; 
    picker.delegate = self; 
    picker.sourceType = UIImagePickerControllerSourceTypeCamera; 

    //Add the OverlayView with the custom Rectangle 
    CGRect overlayFrame = CGRectMake(0.0f, 0.0f, 320.0f, 480.0f); 
    OverlayView *overlayView = [[OverlayView alloc]initWithFrame:overlayFrame]; 
    picker.cameraOverlayView = overlayView; 
    [overlayView release]; 

    [self presentModalViewController:picker animated:YES]; 
    [picker release]; 
} 
} 

回答

1

您不可以做別的事比你已經做什麼其他的;如果iOS決定將覆蓋視圖放在快門上,您只需要忍受它(除非您想冒着被應用商店拒絕的風險)。

作爲不完美的解決方法,您可以使用alpha = 0開始覆蓋,然後在一秒鐘或兩秒後將alpha設置爲1。但是沒有設置快門出現在「打開」之前的時間段(我認爲這取決於初始化相機硬件需要多長時間),所以有時您的界面可能會出現很晚纔出現,有時可能顯得過早。

+0

嗯。我喜歡你對這項工作的想法,但是像你指出的那樣是行不通的。 – Aaronium112 2011-03-29 16:08:10

2

在iPad上,此問題不存在,默認情況下覆蓋視圖位於快門動畫後面。但在iPhone上,覆蓋圖出現在前面。

我找到了適合我的解決方案。

你必須設置您的覆蓋圖在本方法的子視圖:

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated { 
    if (!viewController) 
     return; 

    UIView* controllerViewHolder = viewController.view; 
    UIView* controllerCameraView = [[controllerViewHolder subviews] objectAtIndex:0]; 
    UIView* controllerPreview = [[controllerCameraView subviews] objectAtIndex:0]; 
    [controllerCameraView insertSubview:self.overlayView aboveSubview:controllerPreview]; 
} 

希望它可以幫助

原始來源: http://www.alexcurylo.com/blog/2009/06/18/uiimagepickercontroller-in-3-0/

+0

偉大的這正是什麼工程! – gtgaxiola 2013-08-15 20:26:15

0

我回答了類似的問題here。對我來說(在iOS 6中)是在navigationController中設置cameraOverlayView:willShowViewController:animated。

- (void) navigationController:(UINavigationController*) navigationController willShowViewController:(UIViewController*) viewController animated:(BOOL) animated { 
    self.imagePickerController.cameraOverlayView = ...; // your camera overlay view 
}