How to force portrait orientation in iOS 7
if my application is initially supported for both orientations?
Asked
Active
Viewed 4,498 times
5

Binarian
- 12,296
- 8
- 53
- 84

user3664548
- 59
- 1
- 4
-
1Not clear can you explain more. Do you need only portrait mode in entire app – Gajendra Rawat May 22 '14 at 10:33
-
1possible 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 Answers
6
For the entire app, open the project file, go to the General tab, change the settings:
Or directly on the Info.plist file:
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
-
May this code not according to apple's standard,not sure..But its good hack. – Divya Bhaloidiya May 22 '14 at 10:47
-
When we use this code then our app will not be get approved by the Apple for production. – Prabhu Natarajan May 22 '14 at 10:56
-
1Can you explain why this works, please? Also, those methods were deprecated in iOS 6. It's possible that Apple decides to remove them in iOS 8. It wouldn't be the first time a method was deprecated by Apple and removed shortly after. – rtiago42 May 22 '14 at 10:56
-
@PrabhuNatarajan how you can say that it will get rejected from apple , where you find such statement – Pawan Rai May 22 '14 at 11:20
-
1
-
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