My application is in landscape mode and i want to open gallery and select video but i am getting error. is there any way to use UIImagePickerController in landscape mode or any other alternative way?
Asked
Active
Viewed 893 times
0
-
[Check This link For Landscape App](http://stackoverflow.com/questions/12551247/autorotate-a-single-uiviewcontroller-in-ios-6-with-uitabbar) & http://stackoverflow.com/questions/19374237/using-uiimagepickercontroller-in-landscape-orientation – Varinder Singh iPhone Dev Jun 13 '16 at 12:16
2 Answers
0
- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskLandscape;
}
This should work. If your app only allows portrait. You have to do some extra work in the app delegate. You need to set a boolean property, call it restrictRotation. Then include AppDelegate.h in your class and set restrictRotation to true when you need to rotate it
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
if(self.restrictRotation)
return UIInterfaceOrientationMaskPortrait;
else
return UIInterfaceOrientationMaskAll;
}
Then in your class
- (void) orientationChanged:(NSNotification *)note
{
UIDevice * device = note.object;
switch(device.orientation)
{
case UIDeviceOrientationPortrait:
//do stuff
break;
case UIDeviceOrientationLandscapeLeft:
//do stuff
break;
case UIDeviceOrientationLandscapeRight:
//do stuff
break;
default:
break;
};
}
-(void) restrictRotation:(BOOL) restriction
{
AppDelegate* appDelegate = (AppDelegate*)[UIApplication sharedApplication].delegate;
appDelegate.restrictRotation = restriction;
}
That should help

Kyle Griffith
- 114
- 10
0
In your ViewController.m
:
Make the SubClass(ViewController) of Image Picker Controller
@interface ViewController : UIImagePickerController
@end
@implementation ViewController
// Disable Landscape mode.
- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskLandscape;
}
@end
Use the following code:
UIImagePickerController* picker = [[ViewController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.delegate = self;
// etc.... do like Just as Default ImagePicker Controller
But make sure you check Portrait in deployment info,
because UIImagePickerController
only supports Portrait mode.
If you don't support portrait "globally" the image picker will crash as it has no usable orientations.

Suraj Sukale
- 1,778
- 1
- 12
- 19