2011-08-28 41 views
9

根據UIActionSheet的結果,我正在使用以下功能激活設備照相機或圖像選取器。如果fromCamera = YES,那麼它可以在iPhone和iPad上運行。如果fromCamera = NO,那麼它在iPhone上工作,圖像選擇器出現。但它在iPad上崩潰,出現以下錯誤:UIStatusBarStyleBlackTranslucent在此設備上不可用。我已經知道iPad無法顯示UIStatusBarStyleBlackTranslucent狀態欄,但我該如何避免這種崩潰?崩潰iPad照片選取器

-(void)addPhotoFromCamera:(BOOL)fromCamera{ 

if(fromCamera){  
    picker.sourceType = UIImagePickerControllerSourceTypeCamera; 
} 
else{ 
    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 
} 


[self presentModalViewController:picker animated:YES]; 

}

+0

當然有人在iPad上使用UIImagePickerControllerSourceTypePhotoLibrary? – wasabi

回答

3

我懷疑UIImagePicker從您的Info.plist文件或從當前顯示視圖控制器繼承了半透明的狀態欄。

如果您的應用沒有半透明的狀態欄會發生什麼?

4

如果您的選擇器設置爲UIImagePickerControllerSourceTypePhotoLibrary在iPad上,那麼你就必須出示其在popoverview(!) ,否則你會得到例外。我不喜歡這樣,到ATLEAST控制酥料餅的大小(標準尺寸太小,在我看來):

-(void)openPhotoPicker 
{ 
    imagePicker = [[UIImagePickerController alloc] init]; 
    imagePicker.delegate = self; 
    imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 
    imagePicker.navigationBar.opaque = true; 

    //put the image picker in its own container controller, to control its size 
    UIViewController *containerController = [[UIViewController alloc] init]; 
    containerController.contentSizeForViewInPopover = rightPane.frame.size; 
    [containerController.view addSubview:imagePicker.view]; 

    //then, put the container controller in the popover 
    popover = [[UIPopoverController alloc] initWithContentViewController:containerController]; 

    //Actually, I would like to do the following, but iOS doesn't let me: 
    //[rightPane addSubview:imagePicker.view]; 

    //So, put the popover over my rightPane. You might want to change the parameters to suit your needs. 
    [popover presentPopoverFromRect:CGRectMake(0.0, 0.0, 10.0,0.0) 
        inView:rightPane 
    permittedArrowDirections:UIPopoverArrowDirectionLeft 
        animated:YES]; 

    //There seems to be some nasty bug because of the added layer (the container controller), so you need to call this now and each time the view rotates (see below) 
    [imagePicker.view setFrame:containerController.view.frame]; 
} 

我還有以下,以對抗旋轉錯誤:

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { 
    if(imagePicker!=nil && rightPane.frame.size.width>0) 
     [imagePicker.view setFrame:imagePicker.view.superview.frame]; 
} 

這並不完美,但目前我的測試目的可以。我考慮編寫自己的Imagepicker,因爲我不喜歡被迫使用popoverview ......但是,那是一個不同的故事。