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;
Related
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];
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;
}
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.
In my iphone app, i've two view controllers. First one is a portrait and second one is landscape.
When app is started, it will show the portrait view. On click of a button in portrait view, the view transitions to landscape view. Here, i'm using navigation controller.
If both the views are portrait, pushing the next view via navigation controller won't be a problem. How can I achieve transition between portrait and landscape views using nav controller.
Note that status bar is visible and nav bar is hidden.
I would suggest you to use the following instead of pushViewController
[self presentModalViewController:aController animated:YES];
This is the only solution i guess. If you are navigating further from the LandScape mode put the aController inside the UINavigationController and Present the NavController the same way as shown above.
Quick problem:
I have an UITabBarController with 2 navigation controllers [lets call them Left and Right Controller]
On the default selected Left Controller I can push a new View Controller that detects interface orientation.
On the Right Controller I can push the same View Controller but it won't detect interface orientation, or for that matter, It won't even go into the shouldAutoRotateInterface method at all T___T
Haaalp!!
If it is of any relevance, the View Contoller that I'm pushing use the hidesBottomBarWhenPushed property.
Most likely this is your problem:
Tab bar controllers support a portrait
orientation by default and do not
rotate to a landscape orientation
unless all of the root view controllers support such an orientation.
When a device orientation
change occurs, the tab bar controller
queries its array of view controllers.
If any one of them does not support
the orientation, the tab bar
controller does not change its
orientation.
The solution is to override the following method on every view controller leading to your view:
- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation {
return YES;
}
For example, instead using the default UITabBarController in IB, replace it with your own subclass containing just the method above.
I'm a bit late to the party on this, but I ran into a problem with autorotation at startup for a tab bar app I wanted always to run in portrait.
The app's plist has the necessary settings to both start in and only allow portrait mode, and all my view controllers only allow portrait mode. Yet, when I started the app holding my iPhone in landscape, the app started in portrait, but then rotated to landscape!
Rather than subclass UITabBarController, I simply overrode UITabBarController's shouldAutorotateToInterfaceOrientation: method using a category on class UITabBarController. I included this code in my app delegate:
#implementation UITabBarController(UITabBarControllerCategory)
-(BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)toInterfaceOrientation
{
return (toInterfaceOrientation == UIInterfaceOrientationPortrait);
}
#end
Works beautifully, and is quite lightweight.
does your uitabbarcontroller implement the auto rotate? any child viewcontroller that wants to implement autorotate has to have its parent implement autorotate.