ios - 我可以将现有的 Popover 用于 UIImagePickerController 吗?

标签 ios swift ios8 uipopovercontroller

我可以使用现有的 UIPopoverController 和 UINavigationController 来显示 UIImagePickerController 吗?

我已经尝试了很多,但打开 UIImagePickerController 的唯一方法是关闭现有的 Popover 并打开一个新的。但我想将现有的与我的 UINavigationController 一起使用。

我的 iPad 应用程序有一些具有不同操作(在弹出窗口中)的按钮 - 如果用户选择“图像”,则还有另一个带有“来自现有图像”或“来自相机”的 View Controller - 如果我使用“现有图像” "我想在我现有的 Popover Controller 中打开 Photolibrary(因为当用户选择一个图像时,我想转到我的 UINavigationController 中的下一个 ViewController)

Atm 我在这里打开我的弹出窗口:

var popoverAddItems = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("popoverAddItems") as PopoverAddItemsViewController
var navigationPopover:UINavigationController!
var popover:UIPopoverController!

...

navigationPopover = UINavigationController(rootViewController: popoverAddItems)
popover = UIPopoverController(contentViewController: navigationPopover)
popover.popoverContentSize = CGSizeMake(320,120)
popover.presentPopoverFromRect(currentCell.LabelCellTitle.frame, inView: currentCell.LabelCellTitle.superview!, permittedArrowDirections: UIPopoverArrowDirection.Left, animated: true)

好的,现在我在我的 popoverAddItems ViewController 上,但是我怎么才能到这里,在这个 UINavigationController 中添加一个照片库?

所以我可以在关闭现有 Popover 时使用它:

var imagePickerViewController = PopoverImagePickerViewController()
imagePickerViewController.modalPresentationStyle = UIModalPresentationStyle.Popover
popover = UIPopoverController(contentViewController: imagePickerViewController)
popover.popoverContentSize = CGSizeMake(320,120)
popover.presentPopoverFromRect(currentCell.LabelCellTitle.frame, inView: currentCell.LabelCellTitle.superview!, permittedArrowDirections: UIPopoverArrowDirection.Left, animated: true)

有什么想法吗?任何帮助将不胜感激

最佳答案

要在弹出框内显示一个 UIImagePickerController(在您的例子中是一个 UIPopoverController 内的一个 UINavigationController),请在您的“showImagePicker:”例程中使用以下代码:

    UIImagePickerController* imagePickerController = [[UIImagePickerController alloc] init];
    imagePickerController.delegate = self;
    imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;  // Use your type here
    imagePickerController.modalInPopover = YES;
    imagePickerController.modalPresentationStyle = UIModalPresentationCurrentContext;

    [self.navigationController presentViewController:imagePickerController animated:YES completion:NULL];

当您从 UINavigationControllers viewController 层次结构中调用它时,一切正常。如果您从其他地方调用它,请确保您使用 UIPopoverController 中使用的 UINavigationController 项来呈现 UIImagePickerController。

关于ios - 我可以将现有的 Popover 用于 UIImagePickerController 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25729182/

相关文章:

ios - UIButton - 当调用触摸重复时防止调用触摸事件

ios - Realm -iOS : Model object becomes nil when it's added to realm

iOS 从 UIWebview 内容创建 pdf

ios - 如何在 Swift 中使用 GRDB 创建多对多关联?

ios - 在 iOS 应用内购买中恢复购买

ios - 当显示 StoreKit 确认警报时不再调用 applicationWillEnterForeground(和其他 UIApplication Delegate 函数)

ios - 如何阻止外部资源加载到 WKWebView 上?

ios - 如何将语音合成器静音

ios - 在 Release模式下未调用 Swift 应用程序功能

ios - iOS 8上的墙纸