2011-08-28 92 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 ......但是,那是一个不同的故事。