5

How to force portrait orientation in iOS 7 if my application is initially supported for both orientations?

Binarian
  • 12,296
  • 8
  • 53
  • 84
user3664548
  • 59
  • 1
  • 4
  • 1
    Not clear can you explain more. Do you need only portrait mode in entire app – Gajendra Rawat May 22 '14 at 10:33
  • 1
    possible duplicate of [Force portrait orientation while pushing from landscape View Controller](http://stackoverflow.com/questions/14633213/force-portrait-orientation-while-pushing-from-landscape-view-controller) – Tomer Even May 22 '14 at 10:41

4 Answers4

6

For the entire app, open the project file, go to the General tab, change the settings:

enter image description here

Or directly on the Info.plist file:

enter image description here

If you only want it on a specific view controller, override supportedInterfaceOrientations:

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

You can read more about the second method at the official UIViewController documentation. Maybe, you'll find a more suitable way for your specific problem.

rtiago42
  • 572
  • 3
  • 9
  • Simple and right, but take care to the -(BOOL)shouldAutorotate method. It must not be overridden, or returns YES, otherwise it won't work. – Moose Dec 28 '14 at 19:00
2
UIViewController *c = [[UIViewController alloc]init];
[self presentViewController:c animated:NO completion:nil];
[self dismissViewControllerAnimated:NO completion:nil];
Tariq
  • 9,861
  • 12
  • 62
  • 103
0

Use Following approach : 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(flagOrientationAll == YES){
        return UIInterfaceOrientationMaskPortrait;
    } else {
        return UIInterfaceOrientationMaskAll;
    }
}

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;
}

Here is my thread some what similar to your problem : iOS 7 Interface Orientation

Community
  • 1
  • 1
Divya Bhaloidiya
  • 5,018
  • 2
  • 25
  • 45
-3
#import <objc/message.h>

objc_msgSend([UIDevice currentDevice], @selector(setOrientation:), UIInterfaceOrientationLandscapeRight);//here you may change your desired Orientation
Macrosoft-Dev
  • 2,195
  • 1
  • 12
  • 15