Using UIImagePickerController in landscape orientation
If you'd like to use UIImagePickerController in landscape mode, use user1673099's answer, but instead of:
- (BOOL)shouldAutorotate
{
return NO;
}
use:
- (UIInterfaceOrientationMask)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskLandscape;
}
and then the picker would open in landscape mode:
But make sure you check Portrait in deployment info:
Use UIImagePickerController in landscape mode in Swift 2.0
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
}
}
UIImagePickerController in Landscape
I haven't checked whether this is illegal, but it worked for me.
If you want the UIImagePickerController to start(and stay) in Landscape orientation code:
//Initialize picker
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
//set Device to Landscape. This will give you a warning. I ignored it.
//warning: 'UIDevice' may not respond to '-setOrientation:'
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];
//Set Notifications so that when user rotates phone, the orientation is reset to landscape.
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
//Refer to the method didRotate:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didRotate:)
name:@"UIDeviceOrientationDidChangeNotification" object:nil];
//Set the picker source as the camera
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
//Bring in the picker view
[self presentModalViewController:picker animated:YES];
The method didRotate:
- (void) didRotate:(NSNotification *)notification
{
//Maintain the camera in Landscape orientation
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];
}
Force landscape orientation in UIImagePickerController
As per the UIImagePickerController Class Reference
Important: The
UIImagePickerController
class supports portrait mode only. This class is intended to be used as-is and does not support subclassing. The view hierarchy for this class is private and must not be modified, with one exception. You can assign a custom view to the cameraOverlayView property and use that view to present additional information or manage the interactions between the camera interface and your code.
So it looks like forcing landscape mode is unsupported and discouraged, unless you do so by replacing the default controls with a custom cameraOverlayView
.
open UIImagePickerController in landscape mode
You can't. Quoth the documentation:
The
UIImagePickerController
class supports portrait mode only. This class is intended to be used as-is and does not support subclassing.
It's a bit more work, but you can use the AssetsLibrary framework to access the list of images and create your own image picker.
Related Topics
How to Add a Custom Separator to Uitableviewcell
Ciimage Display Mtkview VS Glkview Performance
iOS Facebook Sdk 3.1 Retrieve Friend Birthday Returning Null
Crashlytics Does Not Show Crashes
iOS Calculate Text Height in Tableview Cell
Is This a Bug with Mkmapkitdelegate Mapview:Didupdateuserlocation
iOS Lazy-Loading of Table Images
Using Wcsession with More Than One Viewcontroller
How to Localize Label Strings in iOS for a Beginner
Creating an Image Out of the iOS Surface and Saving It
Didbegincontact Is Being Called Multiple Times for the Same Skphysicsbody
How to Make Skscene Have Fixed Width
How to Get Nsdate with Millisecond Accuracy
How to Overlay a Skscene Over a Scnscene in Swift
I Just Want to Open Ms Outlook App and See Mailto Screen Using Url Scheme at iOS