I am trying to open a view in landscape by pushing on navigation controller but it always open in portrait.
First view is in portrait and when I click on a button then next view should be in landscape.
I am trying following code
Calling View:
ResultViewController *resultView = [[ResultViewController alloc] init];
[[self navigationController] pushViewController:resultView animated:YES];
View that should open in landscape:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}
Is there something else to try here?
Thanks
Try..
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
//return UIInterfaceOrientationIsLandscape(interfaceOrientation);
return ((interfaceOrientation == UIInterfaceOrientationLandscapeRight) || (interfaceOrientation == UIInterfaceOrientationLandscapeLeft));
}
and then...
- (void)viewDidLoad {
[[UIApplication sharedApplication] setStatusBarOrientation:UIDeviceOrientationLandscapeLeft animated:YES];
}
in resultView
Related
The root view controller of navigation controller supports only portrait orientation and other controllers supports all orientation.Now if i am on the root view controller and the DEVICES is in landscape and if i push next view controller that opens in portrait that should open in landscape as it supports all orientation.
Please help me with this.
Using iPhone 4s iOS6.1.3
you can check Device orientation in your first screen after login viewcontroller using bellow code:-
-(void)viewWillAppear:(BOOL)animated
{
[self willRotateToOrientation:[[UIDevice currentDevice] orientation]];
[super viewWillAppear:YES];
}
- (void)willRotateToOrientation:(UIInterfaceOrientation)newOrientation {
if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation))
{
if (newOrientation == UIInterfaceOrientationLandscapeLeft || newOrientation == UIInterfaceOrientationLandscapeRight) {
//set your landscap View Frame
[self supportedInterfaceOrientations];
}
}
else if (UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation))
{
if(newOrientation == UIInterfaceOrientationPortrait || newOrientation == UIInterfaceOrientationPortraitUpsideDown){
//set your Potrait View Frame
[self supportedInterfaceOrientations];
}
}
// Handle rotation
}
sor when you load this viewcontroller it check first device oriantation and then load it's related frame
I think this is the issue related to the orientation changes in iOS6. You need to subclass the UINavigationController
Check this
1 . You have to create sub class of UINavigationController. add Following method.. Take one boolean variable to check whether it support for all orientation or not and change its value.
#implementation NavigationControllerViewController
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
AppDelegate *appdelgate=[[UIApplication sharedApplication]delegate];
if (appdelgate.issuppoertAll) {
// for iPhone, you could also return UIInterfaceOrientationMaskAllButUpsideDown
return UIInterfaceOrientationMaskAll;
}
return UIInterfaceOrientationMaskPortrait;
}
#end
2 when you navigate form root view controller to other view controller
use this code , when you want to forcefully change its orientation.i.e lanscape to portrait
obj_viewcontroller = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
[self presentModalViewController:obj_viewcontroller animated:NO];
[self dismissModalViewControllerAnimated:NO];
[self.navigationController pushViewController:obj_viewcontroller animated:NO];
3 In second view controller you have to change boolean variable value
-(void)viewWillAppear:(BOOL)animated
{
appdelgate.issuppoertAll=YES;
}
4 Add this method into all view controller and set orientation as per your need.
- (NSInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
I'm calling up a UINavigationController and usually allowing it to use any major orientation:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
// return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
BOOL isAllowed;
if ([allowedOrientations isEqualToString:#"portrait"]) {
isAllowed = (interfaceOrientation == UIInterfaceOrientationPortrait ||
interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);
} else if ([allowedOrientations isEqualToString:#"landscape"]) {
isAllowed = (interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
interfaceOrientation == UIInterfaceOrientationLandscapeRight);
} else {
isAllowed = YES;
}
return isAllowed;
}
From there I call a UITableViewController:
myTable = [[SimpleDocViewerTable alloc] initWithFrame:thisFrame];
self = [super initWithRootViewController:myTable];
Where:
#interface SimpleDocViewerTable : UITableViewController {
The table view controller and navigation controller mostly seem integrated correctly. When I push a new page onto the navigation controller, it correctly scrolls right to left, no matter which orientation I'm using:
SimpleDocPageVC *thisVC = [[SimpleDocPageVC alloc] initWithView:docView];
thisVC.title = [[[tableEntries objectAtIndex:indexPath.section]
objectAtIndex:indexPath.row] objectForKey:#"title"];
[self.navigationController pushViewController:thisVC animated:YES];
However, when I exit that pushed page, if the iPhone is in landscape mode, it scrolls bottom to top, rather than right to left.
The popViewController is all taken care of magically within the automatic "back" button that's generated, so it should be doing the right thing ... but doesn't.
Could it be that one of your controllers (SimpleDocViewerTable, or SimpleDocPageVC) does not support both orientation in shouldAutorotateToInterfaceOrientation?
I am making app like whenever the device change it's orientation mode it changes it's view.
At first when the view is portrait it shows perfect SearchViewController, then when i rotate to landscape it push to new view MapView in landscape ... now when i again change the view to portrait the map rotate to portrait... but it should be do to search view controller... and one more thing when i tapped detail disclosure button it should be go to back to search view controller... i think navigation controller not work in map view..
this is my code part of searchViewController
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
//return (interfaceOrientation == UIInterfaceOrientationPortrait);
if(interfaceOrientation == UIInterfaceOrientationPortrait|| inte rfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
}
else {
MapView *mapView = [[MapView alloc] initWithNibName:#"MapView" bundle:nil];
mapView.title = #"Map";
[self.navigationController pushViewController:mapView animated:YES];
return YES;
}
return YES;
}
and this is my MapView code
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
// return (interfaceOrientation == UIInterfaceOrientationLandscapeRight|| UIInterfaceOrientationLandscapeLeft);
if(interfaceOrientation == UIInterfaceOrientationPortrait|| interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
NSLog(#"hi Potrait");
[self.navigationController popViewControllerAnimated:NO];
return YES;
}
else {
}
return YES;
}
shouldAutorotateToInterfaceOrientation: is an incorrect place to implement any kind of navigation. You should do it in didRotateFromInterfaceOrientation: instead. Check the current interfaceOrientation and push or pop if necessary.
In searchViewController,
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
if ( UIInterfaceOrientationIsLandscape(self.interfaceOrientation) ) {
MapView *mapView = [[MapView alloc] initWithNibName:#"MapView" bundle:nil];
mapView.title = #"Map";
[self.navigationController pushViewController:mapView animated:YES];
}
}
In MapView,
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
if ( UIInterfaceOrientationIsPortrait(self.interfaceOrientation) ) {
[self.navigationController popViewControllerAnimated:NO];
}
}
And alter your shouldAutorotateToInterfaceOrientation: to
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
So I have a UITableViewControler displaying a tableview in portrait mode.
As soon as i rotate the iPhone i want to present a modal view in landscape mode.
In the tableView i use:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
And to handle the present the modal view:
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation duration:(NSTimeInterval)duration {
if((interfaceOrientation == UIInterfaceOrientationLandscapeRight) || (interfaceOrientation == UIInterfaceOrientationLandscapeLeft))
{
NSLog(#"Push page view");
PagingViewController *s = [[PagingViewController alloc] initWithNibName:#"PagingView" bundle:nil];
s.hidesBottomBarWhenPushed = YES;
[self presentModalViewController:s animated:YES];
[s release];
}
}
The modal view i have the following:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
And to dismiss the modal view it self, I do:
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation duration:(NSTimeInterval)duration {
if (interfaceOrientation == UIInterfaceOrientationPortrait)
{
NSLog(#"Dismiss my self");
[self.parentViewController dismissModalViewControllerAnimated:YES];
}
}
Some how this works two times.
The third time i rotate the iPhone from Portrait mode to Landscape mode, i get a bad access error.
I cant figure out what gives me the error.
Anyone care for a shot?
The simplest way I can think of is to implement -shouldAutorotate... and dismiss the modal view and return NO to abort rotation. Perhaps that will be sufficient to avoid any concurrency issues. If this suggestion isn't to your liking take a look at NSNotificationCenter.
I am trying to load a view with the shouldAutorotateToInterfaceOrientation method, but I have a problem. When the device runs as landscape, I want to show the main view itself, and when when the device is portrait, load a custom UIView.
Here is my code:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
if ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft)|| (interfaceOrientation == UIInterfaceOrientationLandscapeRight))
//doesn't show main view !!
self.view;
else if ((interfaceOrientation == UIInterfaceOrientationPortrait) || (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown))
//works fine !
self.view = portraitView;
return YES;
}
I figured out !!!! just call the view with modal on a method
- (void) mainView {
screenTestViewController *mv = [[screenTestViewController alloc]initWithNibName:#"screenTestViewController" bundle:nil];
[self presentModalViewController:mv animated:NO];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
if ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft)|| (interfaceOrientation == UIInterfaceOrientationLandscapeRight))
[self mainView];
.
.
.
You should push your custom UIView in: willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration