Reputation: 470
I am coding a LandScape only iPad application and i need to take pictures from library to send a database but image upload screen only works on Portrait mode. How do i change it to landscape mode? I've read something about UIPickerControllerDelegate doesn't support the Landscape mode but some of the apps ( such as iMessage ) is already using this.
here is my code:
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)
}
}
Upvotes: 5
Views: 6437
Reputation: 1179
It absolutely supports landscape mode. Put this extension somewhere. Best in a file named UIImagePickerController+SupportedOrientations.swift
extension UIImagePickerController
{
public override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
return .Landscape
}
}
This makes all UIImagePickerControllers in your app landscape. You can also subclass it and override this method to make only a subclass landscape-able:
class LandscapePickerController: UIImagePickerController
{
public override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
return .Landscape
}
}
Finally, to support all orientations you can return
return [.Landscape, .Portrait]
For Swift 3:
extension UIImagePickerController
{
override open var shouldAutorotate: Bool {
return true
}
override open var supportedInterfaceOrientations : UIInterfaceOrientationMask {
return .all
}
}
Upvotes: 23