Alright, since no one answered my previous question, I have come to believe that there may be no easy way to do this. But I am optimistic. Here's my issue:
In my app, I am switching from ViewControllerOne to ViewControllerTwo by using a regular UIButton. ViewControllerOne is always in landscape mode. ViewControllerTwo is supposed to be always in portrait mode. However, when I push the button in my landscape ViewControllerOne, ViewControllerTwo is also in landscape mode, although I want it to switch to portrait mode regardless of how the device is rotated by the user when the button is pressed.
I added the following code to my AppDelegate:
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
NSUInteger orientations = UIInterfaceOrientationMaskAll;
if (self.window.rootViewController) {
UIViewController* presented = [[(UINavigationController *)self.window.rootViewController viewControllers] lastObject];
orientations = [presented supportedInterfaceOrientations];
}
return orientations;
}
And I added this to my ViewController that's supposed to be in portrait mode only:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (BOOL)shouldAutorotate
{
return NO;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
-(void)viewWillAppear:(BOOL)animated
{
UIApplication* application = [UIApplication sharedApplication];
application.statusBarOrientation = UIInterfaceOrientationPortrait;
}
Is there a way to tell the viewController to go into portrait mode, even if the previous view was landscape? Maybe I could create a custom segue that would force the view to be in portrait mode when the button is pushed? What would be the best/official solution here?