iOS7 iPad Landscape only app, using UIImagePickerController
If your iPad app is landscape only in all conditions, just do these 3 steps :
1) In your app delegate
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
return UIInterfaceOrientationMaskAll;
}
2) Create a category header
#import "UIViewController+OrientationFix.h"
@implementation UIViewController (OrientationFix)
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
}
- (BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;
}
@end
3) Create a category implementation
#import "UIImagePickerController+OrientationFix.h"
@implementation UIImagePickerController (OrientationFix)
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
}
- (BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;
}
@end
Note: You don't need to import these categories anywhere, just enough they are compiled with the project
Note: no need to implement these methods in any VC
Note: no need to change your plist supported orientations
This is tested and working under any conditions
iOS 7 Landscape only app can't access photo library
yes, I have similar issue in an app
you can add Portrait mode support to app but limit all other views to only support landscape,
mode, then image picker will work
UIImagePickerViewController
only works on portrait mode
to restrict other views only support landscape mode, override - (NSUInteger)supportedInterfaceOrientations in your view controller
- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskLandscape;
}
Landscape only iPad app displays UIImagePicker in portrait orientation
OK, I solved this, the issue was that I was presenting the UIImagePickerController
in a UIPopover
which Apple says not to do when the source type is the camera, instead present it full screen just like you would any other view controller.
Hope this helps someone else too...
Orientation issue in Landscape mode while opening camera in iOS 7 in iPhone
I found my solution from the link iOS7 iPad Landscape only app, using UIImagePickerController.
It worked for me like a charm.
Hope it help someone else also.
Thanks for your help people.
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];
}
Related Topics
Get Pixel Data as Array from Uiimage/Cgimage in Swift
Preferredinterfaceorientationforpresentation Must Return a Supported Interface Orientation
Screenshot Showing Up Blank - Swift
App Not Sized Properly iOS 8 iPhone Simulator
Uiview - How to Get Notified When the View Is Loaded
iPhone Ad Hoc Build Using Xcode 4
Warning: the Copy Bundle Resources Build Phase Contains This Target's Info.Plist File
Xcode 11 Backward Compatibility: "Uiwindowscene Is Only Available in iOS 13 or Newer"
How to Add Strings on X Axis in iOS-Charts
Add Lefthand Margin to Uitextfield
The App References Non-Public Selector in Id (Facebook Sdk iOS)
Does Swift Support Implicit Conversion
Getting Client Certificate to Work for Mutual Authentication Using Swift 3 and Alamofire 4
How to Add the Wechat API to a Swift Project
How to Show a Collectionview Like Facebook Upload Image Using Swift 4
Use a Generic Class as a Custom View in Interface Builder
Exc_Bad_Instruction When Passing Uicollectionview Cell Data to Different Viewcontroller