ios – 在Swift 2.0中以横向模式使用UIImagePickerController

ios – 在Swift 2.0中以横向模式使用UIImagePickerController,第1张

概述我正在编写仅限LandScape的iPad应用程序,我需要从库中拍照才能发送数据库,但图像上传屏幕仅适用于纵向模式.如何将其更改为横向模式?我读过一些关于UIPickerControllerDelegate的东西不支持横向模式,但是一些应用程序(例如iMessage)已经在使用它了. 这是我的代码: class signUpViewController: UIViewController,UIPi 我正在编写仅限LandScape的iPad应用程序,我需要从库中拍照才能发送数据库,但图像上传屏幕仅适用于纵向模式.如何将其更改为横向模式?我读过一些关于UIPickerControllerDelegate的东西不支持横向模式,但是一些应用程序(例如iMessage)已经在使用它了.

这是我的代码:

class signUpVIEwController: UIVIEwController,UIPickerVIEwDataSource,UIPickerVIEwDelegate,UINavigationControllerDelegate,UIImagePickerControllerDelegate {func imagePickerController(picker: UIImagePickerController,dIDFinishPickingImage image: UIImage!,editingInfo: [NSObject : AnyObject]!) {    print("Image Selected")    self.dismissVIEwControllerAnimated(true,completion: nil)    profileImageVIEw.image = image}@IBAction func importimage(sender: AnyObject) {    var image = UIImagePickerController()    image.delegate = self    image.sourceType = UIImagePickerControllerSourceType.Photolibrary    image.allowsEditing = false    self.presentVIEwController(image,animated: true,completion: nil)}}
解决方法 它绝对支持横向模式.把这个扩展放在某个地方.最好在名为UIImagePickerController的文件SupportedOrIEntations.swift中

extension UIImagePickerController{    public overrIDe func supportedInterfaceOrIEntations() -> UIInterfaceOrIEntationMask {        return .Landscape    }}

这使得所有UIImagePickerControllers都在您的应用程序环境中.您也可以对其进行子类化并覆盖此方法,以仅使子类具有横向能力:

class LandscapePickerController: UIImagePickerController{    public overrIDe func supportedInterfaceOrIEntations() -> UIInterfaceOrIEntationMask {        return .Landscape    }}

最后,为了支持所有方向,您可以返回

return [.Landscape,.Portrait]

对于Swift 3:

extension UIImagePickerController    {        overrIDe open var shouldautorotate: Bool {                return true        }        overrIDe open var supportedInterfaceOrIEntations : UIInterfaceOrIEntationMask {                return .all        }}
总结

以上是内存溢出为你收集整理的ios – 在Swift 2.0中以横向模式使用UIImagePickerController全部内容,希望文章能够帮你解决ios – 在Swift 2.0中以横向模式使用UIImagePickerController所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1036485.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-24
下一篇 2022-05-24

发表评论

登录后才能评论

评论列表(0条)

保存