0

我发现很多文章,当谷歌搜索这个,但没有一个似乎真的覆盖这种情况下,所以我会尽量做到非常具体。 我有适用于iPhone和iPad的Landscape only应用程序。我试图让用户从他的专辑中挑选其他图片用下面的代码:UIImagePickerController只从横向选择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 

}) 

我现在用的是酥料饼的表现风格,因为Apple mentions是在iPad上,这是应该怎样设置否则将引发异常:

该表显示,在iPad上,如果指定 photoLibrary或savedPhotosAlbum的源类型,则必须使用酥料饼的控制器出现在图像拾取 (学习如何做到这一点,看到 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假的,但我觉得这是没用的因为在这里失败的类是PUUIAlbumListViewController
  • 设置我的应用程序支持肖像,这个工程,但然后整个应用程序aut与手机otorates,这并不意味着要发生
  • 使用中间UIPopoverPresentationController,但从来没有得到这说明了什么

UPDATE 不是一个答案,但疯狂的,因为它看起来我不认为这是可行的。感谢苹果提供了一切皆有道理的最先进的API。 我结束了使用DKImagePickerController,完成这项工作

回答

0

我有这个问题以及强制景观的应用程序。唯一的选择是放松并允许图像选取器作为肖像来呈现,因为这是其呈现时的默认位置。

0

子类您的导航控制器并更改为横向方向掩码。然后从那个NavigationController显示你的Image Picker控制器。

class CustomNavigation: UINavigationController { 
override func viewDidLoad() { 
    super.viewDidLoad() 

    // Do any additional setup after loading the view. 
} 

override func didReceiveMemoryWarning() { 
    super.didReceiveMemoryWarning() 
    // Dispose of any resources that can be recreated. 
} 
override var shouldAutorotate: Bool { 
    return false 
} 
override var supportedInterfaceOrientations: UIInterfaceOrientationMask { 
    return UIInterfaceOrientationMask.portrait 
} 

/* 
// MARK: - Navigation 
// In a storyboard-based application, you will often want to do a little preparation before navigation 
override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 
    // Get the new view controller using segue.destinationViewController. 
    // Pass the selected object to the new view controller. 
} 
*/ 


} 
相关问题