简体   繁体   English

崩溃的iPad照片选取器

[英]Crash iPad Photo Picker

I am using the following function to activate either the device camera or the image picker depending on the result of a UIActionSheet. 我正在使用以下功能激活设备相机或图像选择器,具体取决于UIActionSheet的结果。 if fromCamera=YES then it works on both iPhone and iPad. 如果fromCamera = YES则适用于iPhone和iPad。 if fromCamera=NO then it works on iPhone and the image picker appears. 如果fromCamera = NO,那么它适用于iPhone并出现图像选择器。 But it crashes on the iPad with the following error: UIStatusBarStyleBlackTranslucent is not available on this device. 但它在iPad上崩溃时出现以下错误: 此设备无法使用UIStatusBarStyleBlackTranslucent。 I already know that the iPad can't display the UIStatusBarStyleBlackTranslucent statusBar, but how do I avoid this crash? 我已经知道iPad无法显示UIStatusBarStyleBlackTranslucent statusBar,但是如何避免这种崩溃呢?

-(void)addPhotoFromCamera:(BOOL)fromCamera{

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


[self presentModalViewController:picker animated:YES];

} }

If you set the picker to UIImagePickerControllerSourceTypePhotoLibrary on the iPad, then you must(!) present it in a popoverview, otherwise you get exceptions. 如果您在iPad上将选择器设置为UIImagePickerControllerSourceTypePhotoLibrary,则必须(!)将其显示在popoverview中,否则您将获得例外。 I do it like this, to atleast control the size of the popover (the standard size is too small in my opinion): 我这样做,至少控制popover的大小(标准尺寸在我看来太小):

-(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];
}

I also have the following, to counter a rotation bug: 我还有以下内容,以对抗旋转错误:

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

It ain't perfect, but it is ok for my testing purposes at the moment. 它并不完美,但目前我的测试目的还可以。 I consider writing my own Imagepicker, because I don't like being forced to use the popoverview... but well, that's a different story. 我考虑编写自己的Imagepicker,因为我不喜欢被迫使用popoverview ......但是,这是一个不同的故事。

I suspect the UIImagePicker is inheriting the translucent status bar from your Info.plist file or from the currently displayed view controller. 我怀疑UIImagePicker是从Info.plist文件或当前显示的视图控制器继承半透明状态栏。

What happens if you make the app not have a translucent status bar? 如果您使应用程序没有半透明状态栏会发生什么?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM