Force Portrait if Previous View Landscape - iphone

I am creating an app that is exclusively in portrait mode, except in one view. It switches to landscape fine, but when using the "back" button to go to the previous view, which should be displayed in portrait, it now is displayed in landscape.
How can I force the UIViewController to be presented in portrait even if the previous controller was landscape?
The following code is no longer working as it was deprecated...
UIViewController *c = [[UIViewController alloc]init];
[self presentModalViewController:c animated:NO];
[self dismissModalViewControllerAnimated:NO];

Based on status bar orientation you can change the device orientation. After clicks the back button check the orientation of device and based on that set the orientation.

Related

iOS6 rotation issue: make my view stick to portrait when pop back from another view controller

I have two viewcontrollers, ViewControllerA supports both landscape and portrait, click a button in ViewControllerA push into ViewControllerB, which supports landscape only, then I make the phone in the landscape direction and then pop back to ViewControllerA, by default A is in landscape mode now, but I want it to be portrait first in this situation. How can I implement that?
In your ViewControllerA's viewwillappear method set the orientation like
[[UIDevice currentDevice]setOrientation:UIInterfaceOrientationPortrait];

Presenting a UIViewController when on landscape orientation

What is the best way to show a UIViewController only when the device is on landscape mode?
The modal view controller should present itself modally when the device is on landscape mode and should dismiss itself when going back to portrait.
Since - (BOOL)shouldAutorotateToInterfaceOrientation :(UIInterfaceOrientation)toInterfaceOrientation is only called once (and not for every UIViewController), how should the navigation controller be set up?
The method you're looking for is
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)o duration:(NSTimeInterval)t;

Change Orientation forcefully

In my app, While playing video user can play in full screen in both orientation landscape and portrait. But while move back to original position from full screen, i want to change my controller's orientation to portrait if its running in landscape.
Its working fine if i push that controller, but i have to present it. So its not working with presented controller.
I m using code as below to make it portrait.
[appdel.navigationController.presentedViewController.view removeFromSuperview];
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait];
[[UIApplication sharedApplication].self.delegate.window addSubview:[appdel.navigationController.presentedViewController.view];
self.navigationController.navigationBar.hidden=NO;
Thanks for any help
see in case of presenting the controller when u come in previous controller the
viewWillApear: of previous method will call so change your orientation in viewWillApear: mthod

Rotate a UIViewController

I have a navigation view controller. When i select a tableview cell it push a new ViewController from UIInterfaceOrientationPortrait state.
Now if i Rotate the new ViewController Landscape mode and pop the new ViewController and go back the table view Navigation Controller main page then i can see that, NavigationController main page is its previous UIInterfaceOrientationPortrait mode and i can't see the downstair part of my tableView interface.
How i am gonna fixed this such a way that if i pop up the newViewController, the Main Navigation ViewController page will view such a way that achieve the Orientation mode of newViewController.
That mean's if the newViewController is in landscape mode than the main page will automatically landscape mode and if the newViewController is in Portrait mode then the main Navigation page will be automatically Portrait mode.
Any solution ????
Add the following in all your view controllers (in the navigation stack) implementation files.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}

How to open new view when device is rotated to landscape orientation?

I have an application which is focused around a bunch of viewControllers in portraitmode, but on a specific detail view i need to open another view if the device is rotated to landscape mode.
So the user will look at the information view in portraitmode and if the user then rotates the device to landscapemode then a new view is displayed with additional information. If the user rotates back to portrait then the added view needs to be removed so the "original" detailview is visible.
It's important that the "original" detailview is not rotated to landscape - Only open a new view in landscape mode.
I've tried using shouldAutorotateToInterfaceOrientation: and managed to have it open a viewController, but it's not being shown in landscape view so it looks all messed up plus I'm having some trouble getting the view to disappear when i rotate back to portraitmode.
How do i do this?
Check if the orientation has changed using the View controllers did change orientation methods and if its rotated to landscape add ur landscape view and when the device is rotated to portrait remove the view from the view controller's view.
in shouldAutorotateToInterfaceOrientation
if(UIInterfaceOrientation == UIInterfaceOrientationPortrait){
NewView *newViewController = [[NewView alloc]initWithNib:#"NewView" bundle:nil];
[self.navigationController pushViewController:newViewController animated:NO];
}
you can repeat this for all the other orientations as well.
Using shouldAutoRotate didn't work since the view that gets opened will be opened in portraitmode and not landscape.
I ended up with a solution using beginGeneratingDeviceOrientationNotifications and shouldAutoRotate in the subview.