UIPopoverPresentationController在iPad中消失了

时间:2016-09-23 05:58:51

标签: ios objective-c ipad uipopovercontroller

我在iPad中使用UIPopoverPresentationController选择相机照片库来选择或拍摄图像。

以下是我的代码,

dispatch_async(dispatch_get_main_queue(), ^{

    UIAlertController *alertController;
    UIAlertAction *destroyAction;
    UIAlertAction *otherAction;

    alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    destroyAction = [UIAlertAction actionWithTitle:@"Camera" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action)
                     {
                         if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
                         {
                             UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
                             [imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
                             [imagePicker setDelegate:self];

                             if ([self respondsToSelector:@selector(presentViewController:animated:completion:)])
                             {
                                 [imagePicker setShowsCameraControls:NO];
                                 [self presentViewController:imagePicker animated:YES completion:^{
                                     [imagePicker setShowsCameraControls:YES];
                                 }];
                             } else
                             {
                                 [self presentViewController:imagePicker animated:YES completion:nil];
                             }
                         }
                         else
                         {
                             UIAlertView *alertCamera = [[UIAlertView alloc]initWithTitle:ALRT message:@"Camera doesn't Support for this Device" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
                             [alertCamera show];
                         }
                     }];

    otherAction = [UIAlertAction actionWithTitle:@"Photo library" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action)
                   {
                       UIImagePickerController *picker;

                       if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
                       {
                           picker = [[UIImagePickerController alloc] init];
                           picker.delegate = self;
                           picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
                       }
                       [self presentViewController:picker animated:YES completion:nil];
                   }];
    [alertController addAction:destroyAction];
    [alertController addAction:otherAction];
    [alertController setModalPresentationStyle:UIModalPresentationPopover];

    UIPopoverPresentationController *popPresenter = [alertController
                                                     popoverPresentationController];
    popPresenter.sourceView = sender;
    popPresenter.sourceRect = sender.bounds;
    [self presentViewController:alertController animated:YES completion:nil];

});

enter image description here

我面临的问题是,消失的UIPopoverPresentationController显示黑屏。不知道出了什么问题!

0 个答案:

没有答案