Set shouldAutorotate to false with Photolibrary

女生的网名这么多〃 提交于 2019-12-07 02:48:20

问题


If I add a popover with access to my photo gallery from the iPad the system always crash with the following message:

Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'Supported orientations has no common orientation with the application, and [PUUIAlbumListViewController shouldAutorotate] is returning YES'

But I already set up in my Projekt Information just to support Landscape Mode.

So I added the following function

override func shouldAutorotate() -> Bool {

    return false
}

But I don't know how to use it? If I enable UIInterfaceOrientationPortrait on my app too, it works fine. But I don't want to support UIInterfaceOrientationPortrait.

I'll call my popover like this:

var popover: UIPopoverController = UIPopoverController(contentViewController: ImagePickerController)

popover.presentPopoverFromBarButtonItem(addImageButton, 
                                        permittedArrowDirections: UIPopoverArrowDirection.Any, 
                                        animated: true)

Any help would be greatly appreciated


回答1:


You have no choice. And in fact you have solved the problem already. As you have already said, the solution is to enable portrait orientation in your app. You don't have to use it in any of your other view controllers, but you must include it in the app's permissible orientations, because this one view controller that you are trying to show requires it. If the intersection between what the view controller requires and what the app permits is null, the app will crash (as you have seen).




回答2:


At a slightly higher level, the problem is that your app only supports landscape and yet the UIImagePickerController requires portrait to be supported in your app (but none of the view controllers, which makes no sense, but anyway...)

So another way to handle this problem is to look for an alternative to UIImagePickerController that does the same thing. Here's one that works well. While the code hasn't been updated in a few years, it is ARC compatible.

https://github.com/B-Sides/ELCImagePickerController

It's pretty fantastic, and helps you avoid lots of madness, especially if you don't want to (or cannot) support portrait modes in your app.



来源:https://stackoverflow.com/questions/25090167/set-shouldautorotate-to-false-with-photolibrary

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!