我在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];
});
我面临的问题是,消失的UIPopoverPresentationController显示黑屏。不知道出了什么问题!