【发布时间】:2016-11-15 18:28:48
【问题描述】:
我在谷歌上搜索时发现了很多文章,但似乎没有一个真正涵盖这个案例,所以我会尽量具体。 我有一个适用于 iPhone 和 iPad 的仅限横向应用程序。我试图让用户使用以下代码从他的相册中挑选一张图片:
let imagePicker = UIImagePickerController()
imagePicker.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
imagePicker.mediaTypes = [kUTTypeImage as String]
imagePicker.modalPresentationStyle = UIModalPresentationStyle.Popover
imagePicker.allowsEditing = false
context.presentViewController(imagePicker, animated: true, completion: {
() -> Void in
})
我正在使用 Popover 演示样式,因为 Apple mentions 在 iPad 上必须这样设置,否则将引发异常:
该表表明,在 iPad 上,如果您指定源类型 photoLibrary 或 savedPhotosAlbum,您必须出示图片选择器 使用 popover 控制器(要了解如何执行此操作,请参阅 UIPopoverPresentationController)。如果您尝试呈现图像 选择器模态(全屏)用于在保存的图片中进行选择和 电影,系统会引发异常。
失败并出现以下错误
*** Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'Supported orientations has no common orientation with the application, and [PUUIAlbumListViewController shouldAutorotate] is returning YES'
我尝试过的:
- 子类 UIImagePickerController 和 UIViewController 以支持横向方向并将 shouldAutorotate 设置为 false,但我认为这没有用,因为这里失败的类是 PUUIAlbumListViewController
- 将我的应用设置为支持人像,这可行,但随后整个应用会自动使用手机,这不会发生
- 使用中间的 UIPopoverPresentationController 但从来没有让它显示任何东西
更新 不是答案,但尽管看起来很疯狂,但我认为这是不可行的。感谢 Apple 提供了最先进的 API,其中一切都有意义。 我最终使用了DKImagePickerController,完美地完成了这项工作
【问题讨论】:
标签: ios swift uiimagepickercontroller uipopovercontroller landscape