当方向只允许横向时,iOS 9 UIImagePickerControllerSourceTypePhotoLibrary 崩溃

标签 ios objective-c ipad ios9.3

我已经创建了只支持横向方向的应用程序,每当我调用 UIImagePickerControllerSourceTypeCamera 以使用相机拍照时都可以,但是当我调用 UIImagePickerControllerSourceTypePhotoLibrary 时它崩溃了。

我曾尝试使用方法 shouldAutoRotate() 允许纵向但仍然无法正常工作。这个问题有什么解决办法吗?

最佳答案

当你在 iPad 上遇到这个错误时

试试下面的代码并为此目的使用 UIModalPresentationStyle :-

                self.imagepicker.modalPresentationStyle = UIModalPresentationStyle.Popover
                let popover = self.imagepicker.popoverPresentationController
                self.imagepicker.preferredContentSize = CGSizeMake(400 ,400)
                popover!.sourceView = self.view
                popover!.sourceRect = CGRectMake(CGRectGetMidX(self.view.bounds), CGRectGetMidY(self.view.bounds),0,0)
                popover!.permittedArrowDirections = UIPopoverArrowDirection(rawValue: 0)
                self.presentViewController(self.imagepicker, animated: true, completion: nil)

这是在 Swift 中,我希望你能轻松地转换到 objective-c。

希望对您有所帮助。

关于当方向只允许横向时,iOS 9 UIImagePickerControllerSourceTypePhotoLibrary 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40017906/

相关文章:

ios - 删除文件时出错

objective-c - 多个模态视图可防止背景变暗/禁用 UIModalPresentationPageSheet

iphone - 在iPad编程中使用多线程时出现问题(用于加载大量图像)

ios - 在特定 iPad 型号上添加 UIView Laggy

objective-c - 使用 objc_msgSend 调用带有命名参数的 Objective C 函数

iphone - 具有不同字符串选项的Plist

iphone - 动态检查类是否通过 respondsToSelector : 响应选择器

ios - 如何在iOS中制作这种效果,模糊效果使其向下方倾斜

ios - 如何找到 ARRAY 的索引位置,其中 NSPredicate 选取值。我使用 filteredArrayUsingPredicate 作为过滤器

ios - Xcode 8 无效的二进制文件