My project has many view controller (.xib file). I want: a view controller can only have portrait orientation. However an other view controller can only have landscape orientation. or a view controller can have both portrait and landscape orientation. Now I want a view controller only have landscape orientation (no portrait orientation). Please help me. Thanks you.
Asked
Active
Viewed 4,364 times
0
-
Check this one [Interface orientation in iOS 6.0](http://stackoverflow.com/questions/12404556/interface-orientation-in-ios-6-0). Let me know your response after trying this. – Parth Bhatt Aug 28 '13 at 10:43
-
Go through http://stackoverflow.com/questions/37085341/how-to-set-certain-view-controller-to-be-landscape-and-portrait-and-certain-to-b/37086217#37086217 – Mahendra Y May 07 '16 at 08:19
1 Answers
0
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return UIInterfaceOrientationIsPortrait(toInterfaceOrientation);
}
UPDATED:
You can do this by creating category of UINaviagationController
code for .h file is
@interface UINavigationController (autorotation)
-(BOOL)shouldAutorotate;
-(NSUInteger)supportedInterfaceOrientations;
and code for .m file is
@implementation UINavigationController (autorotation)
-(BOOL)shouldAutorotate
{
UIInterfaceOrientation interfaceOrientation = [UIApplication sharedApplication].statusBarOrientation;
[self.topViewController shouldAutorotate];
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
@end

Krishna Kumar
- 1,652
- 9
- 17
-
You need to modify the code according to your suitability. I have just given you the generalized form. – Krishna Kumar Aug 28 '13 at 10:50
-