I am having an app which is in Landscape Mode.
The app is designed both for iPhone and iPad.
I am opening Photo Library to access photos from there and also capturing photos from some of my views.
But as of I know, Photo library can only be opened in Portrait Mode, So I select all the orientation from the setting shown below.
I have done the same thing for iPad also.
So I tried this code from all the view.
-(BOOL)shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight ;
}
So that all the views can be locked in portrait mode only.
But my views still shows in portrait mode also.
For Photo Library, I made a different class like below.
@interface NonRotatingUIImagePickerController8 : UIImagePickerController
@end
@implementation NonRotatingUIImagePickerController
- (BOOL)shouldAutorotate
{
return YES;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait ;
}
@end
@interface NonRotatingUIImagePickerController2 : UIImagePickerController
@end
@implementation NonRotatingUIImagePickerController2
- (BOOL)shouldAutorotate
{
return NO;
}
@end
So my photo library is showing in portrait mode but my all other views shows in Portrait Mode.
So How can I solve this issue?
Please help me.
Stuck on this for quite a while.
Thanks in advance....
**Edited**
If I do like this my app shows fully in Landscape mode but it crashes when I try to open photo library.
How Can I do this?
Please help....
I have also faced this situation , and i found solution , see my code below.
First comment all orientation methods that you have written in every class.
then check mark all orientaition like below
now in AppDelegate.m file write below code in which " presented " is UIViewController in which you are trying to open pickerview
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
NSUInteger orientations = UIInterfaceOrientationMaskAll;
if (self.window.rootViewController) {
UIViewController* presented = [[(UINavigationController *)self.window.rootViewController viewControllers] lastObject];
if([presented isKindOfClass:[PhotoVC class]])
{
orientations = [presented supportedInterfaceOrientations];
return orientations;
}
orientations = UIInterfaceOrientationMaskLandscape;
}
return orientations;
}
Now replace code in your NonRotatingUIImagePickerController2
with my code like below
@interface NonRotatingUIImagePickerController2 : UIImagePickerController
@end
@implementation NonRotatingUIImagePickerController2
- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskLandscape;
}
@end
Please check it and let me know it is working or not!!!
Happy Coding!!!
Try this:
Open your storyboard, select the view controllers, then choose "Landscape" in Orientation dropdown:
See this picture: https://www.dropbox.com/s/fnnh8auzuyb2waw/Screenshot%202014-05-06%2013.24.02.png
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.