IOS 7 interface orientation

I have an application that always displays in portrait mode.

But somewhere, I have a media gallery that should support the landscape.

The supported default orientation in the project is portrait. Because of this, the gallery is displayed only in portrait mode.

If I change the project settings to show in portrait and landscape orientation, the gallery works fine, but I can not control other viewControllers so that they are displayed only in portrait.

I tried several methods like shouldAutoRotate, but no one worked.

Any idea how to solve?

Hello

EDIT:

Solved :)

First, I set up the project to support all orientation. Then I added this method to AppDelegate.m:

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

After that, I did to block the orientation in each view controller, less than the one I want to have orientation in landscape and portrait.

Orientation Lock Code (iOS 7):

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

Thanks to everyone who answered me :)

+6
source share
2 answers

In my application for iPhone, only portrait view is supported, but on demand it is necessary to support the landscape for viewing only, while I use the following method and its help:

In your application .h

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

Add the delegate .m file to your application 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 the following method in your view, which you want to rotate in both portrait and landscape terms for the iPhone

 -(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 on iphone?

+7
source

You must make another class in the same Controller view where you represent your media.

In this you can indicate your orientation, where it will only support landscape orientation, only when you present your media.

I give you an example of my application that only supports landscape mode, but when I took Image picker and it only supports portrait mode, so I changed the orientation for that view only.

 #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 the class object that I created.

So, I define as shown below.

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

So For Image Picker It is displayed only in portrait mode.

You just need to change the Landscape instead of the portrait, if you want to use only the landscape orientation for your particular view, where you want to change it.

Hope this helps you.

+1
source

Source: https://habr.com/ru/post/959468/


All Articles