6

I have an app that is always showed in portrait mode.

But in somewhere i have a media gallery that must support landscape.

The supported orientation by default in the project is portrait. Because of that the gallery is only showed in portrait mode.

If i change the project setting to show in portrait and landscape the gallery works fine but i can't control the other viewControllers to show only in portrait.

I tried several methods like shouldAutoRotate but no one worked.

Any ideia how to solve?

Regards

EDIT:

Solved :)

First i configured the project to support all orientation. Then i added this method to the AppDelegate.m:

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
 return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscape;
}

After this what i did was to block orientation in each view controller, less the one i want to have orientation in landscape and portrait.

Code to block orientation (iOS 7):

- (BOOL)shouldAutorotate
{
 return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
 return (UIInterfaceOrientationMaskPortrait);
}

Thanks to everyone that answered me :)

asked Dec 6, 2013 at 11:01
3
  • see my thread also : stackoverflow.com/questions/19422373/… Commented Dec 6, 2013 at 11:23
  • In my case your code does not work. The view is rotated to landscape position even if I specify Portrait both in 'supported' and in 'preferred'. Nothing changes if I set shouldAutorotate to true or false. Commented Feb 26, 2014 at 13:41
  • Same problem I had. iOS 7+ made handling orientation a damn complex thing. Commented Jan 12, 2015 at 8:15

2 Answers 2

7

In my app for iPhone its only support the portrait view only, but as per requirement need to support landscape view only for on view, at that time I use following way and its help me :

In your app delegate .h

@interface PlayWithWSWithLibAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> {
 BOOL flagOrientationAll;
}
@property (assign) BOOL flagOrientationAll;

Add following method in your app delegate .m file

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
 //NSLog(@"PlayWithWSWithLibAppDelegate -- supportedInterfaceOrientationsForWindow");
 if([UICommonUtils isiPad]){
 return UIInterfaceOrientationMaskAll;
 }else if(flagOrientationAll == YES){
 return UIInterfaceOrientationMaskAll;
 } else {
 return UIInterfaceOrientationMaskPortrait;
 }
}

Implement following way in your view which you want to rotate in both portrait and landscape both for iPhone device

-(void)viewWillAppear:(BOOL)animated
{
 self.tabBarController.delegate = self;
 PlayWithWSWithLibAppDelegate *delegate = (PlayWithWSWithLibAppDelegate *) [[UIApplication sharedApplication] delegate];
 delegate.flagOrientationAll = YES;
 }
}
-(void)viewWillDisappear:(BOOL)animated
{
 //NSLog(@"viewWillDisappear -- Start");
 PlayWithWSWithLibAppDelegate *delegate = (PlayWithWSWithLibAppDelegate *)[[UIApplication sharedApplication] delegate];
 delegate.flagOrientationAll = NO;
}

see this post also: How to set one of the screens in landscape mode in iphone?

answered Dec 6, 2013 at 11:15
Sign up to request clarification or add additional context in comments.

1 Comment

Remember to add @synthesize flagOrientationAll; in the app delegate .m file
1

You have to make another class in the same view Controller where you are presenting your media.

In that you can specify your orientation where it will support only landscape orientation only when you will present your media.

I am giving you an example of my app which supports only in landscape mode but as I took Image picker and it supports only in portrait mode so I changed the orientation for only that view.

#pragma mark - Image PICKER
@interface NonRotatingUIImagePickerController : UIImagePickerController
@end
@implementation NonRotatingUIImagePickerController
- (BOOL)shouldAutorotate
{
 return YES;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
 return UIInterfaceOrientationPortrait ;
}
@end

Then when I used ImagePicker I used object of the class that i made.

So I define like below.

UIImagePickerController* picker = [[NonRotatingUIImagePickerController alloc] init];

So For Image Picker It showed only in portrait mode.

You just need to change Landscape instead of portrait if you want only Landscape Orientation for your particular view where you want to change it.

Hope this helps you.

answered Dec 6, 2013 at 11:16

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.