I have an app with 9-10 screens. I embedded a UINavigationController
into my view controller. I have few view controllers which I want set only portrait orientation: it means that rotating the device should not rotate these view controllers to landscape mode. I have tried the following solutions:
first:
NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];
but screen still rotates to landscape.
Second:
I created a custom view controller class as PortraitViewController
and added the code below in PortraitViewController.m
@interface PortraitViewController ()
@end
@implementation PortraitViewController
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
//Here check class name and then return type of orientation
return UIInterfaceOrientationMaskPortrait;
}
@end
After that I implemented PortraitViewController.h
as a base class
#import <UIKit/UIKit.h>
#import "PortraitViewController.h"
@interface Login : PortraitViewController
@end
It does not work at all, still allows view controller to rotate in landscape mode.
Is there any other solution i am using iOS 8 & don't want viewcontroller to rotate in landscape mode?
EDIT: Is it possible to have Landscape orientation only for some view controllers, and force other view controllers orientation to stick to Portrait?
Here is the link to the topic: http://koreyhinton.com/blog/lock-screen-rotation-in-ios8.html
Try adding this method along with
shouldAutorotate
andsupportedInterfaceOrientations
}
Also you can use this
[UIViewController attemptRotationToDeviceOrientation]
So that it rotates to the desired new orientationYour PortraitViewController is ok and I don't know your Storyboard configuration. In your case important thing is you should embedded your target view controller in another new navigation controller, then set it's class to your PortraitViewController and present that navigation modally, like I have done in below image and it's working as expected.
If you want to show animation that will make presentation animation like push animation
Below is mine PortrateNavigation subClass of UINavigationController
PortrateNavigation.h
PortrateNavigation.m