How can I set certain view controller to be landscape and portrait and certain to be landscape only? Thanks .
Asked
Active
Viewed 402 times
2 Answers
2
Step 1. Create a subclass of UINavigationcontroller named like CustomNavController Step 2. initialise CustomNavController instead of UINavigationController in AppdDelegate.
Step 3. override following method of UINavigationController in CustomNavController
-(NSUInteger) supportedInterfaceOrientations
{
if([NSStringFromClass([[[self viewControllers] lastObject] class]) isEqualToString:@"ViewAsset"]){
return UIInterfaceOrientationMaskAll;
}
return UIInterfaceOrientationMaskPortrait;
}
-(BOOL)shouldAutorotate
{
return YES;
}
where ViewAsset is name of class which you need in both mode.
for more interesting tutorials check out https://appengineer.in/

Mahendra Y
- 1,941
- 20
- 26
-
I have a problem i successfully set the orientation but when i present modally from another landscape controller to potrait controller it show landscape. – May 07 '16 at 12:29
1
1) Select the "device orientations" that you want in your project from the "Deployment Info" in the "General" tab.
2) In your view controller class, use this code:
- (UIInterfaceOrientationMask) supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
3) For view controllers that you want to support both orientations:
- (UIInterfaceOrientationMask) supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscape;
}

iOS Geek
- 4,825
- 1
- 9
- 30
-
I have a problem i successfully set the orientation but when i present modally from another landscape controller to potrait controller it show landscape. – May 07 '16 at 12:29
-
@TOP10NEWS - See if this link can help you http://stackoverflow.com/a/27561781/6080920 – iOS Geek May 09 '16 at 04:51