簡體   English   中英

崩潰的iPad照片選取器

[英]Crash iPad Photo Picker

我正在使用以下功能激活設備相機或圖像選擇器,具體取決於UIActionSheet的結果。 如果fromCamera = YES則適用於iPhone和iPad。 如果fromCamera = NO,那么它適用於iPhone並出現圖像選擇器。 但它在iPad上崩潰時出現以下錯誤: 此設備無法使用UIStatusBarStyleBlackTranslucent。 我已經知道iPad無法顯示UIStatusBarStyleBlackTranslucent statusBar,但是如何避免這種崩潰呢?

-(void)addPhotoFromCamera:(BOOL)fromCamera{

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


[self presentModalViewController:picker animated:YES];

}

如果您在iPad上將選擇器設置為UIImagePickerControllerSourceTypePhotoLibrary,則必須(!)將其顯示在popoverview中,否則您將獲得例外。 我這樣做,至少控制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];
}

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

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

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

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

如果您使應用程序沒有半透明狀態欄會發生什么?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM