0
votes

I have another orientation problem. But this one is very tricky. My RootViewController is a normal NavigationController.

self.window.rootViewController = _naviController;

which has another ViewController inside, lets call it VC1. VC1 has some buttons and labels. Its like an overview with folders.

If I press a button I come to the next ViewController with 3 ViewController (Page) and another bunch of buttons (like inside a folder looking at the pictures/thumbnails inside):

Archiv *archiv = [[Archiv alloc] init];
[self.navigationController pushViewController:archiv animated:YES];
[archiv release];

in loadView:

firstPage = [[Page alloc] initViewWithFrame:CGRectMake(0, 0, 768, 960)];
[firstPage setRootViewController:self];
secondPage = [[Page alloc] initViewWithFrame:CGRectMake(0, -960, 768, 960)];
[secondPage setRootViewController:self];
thirdPage = [[Page alloc] initViewWithFrame:CGRectMake(0, 960, 768, 960)];
[thirdPage setRootViewController:self];

If I now click again on a button the active Page push my third ViewController (image with resizing, dragging...):

Picture *pic = [[Picture alloc] initWithPicURLString:urlString];
[rootViewController.navigationController pushViewController:pic animated:YES];
[pic release];

With the BackButton of the NavigationController I can always come back to the previous view.

Some more informations:

  • Every ViewController supports all orientations
  • Every ViewController implements - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation with return YES;
  • Every ViewControler calls the [super init] in their init-methode
  • I already read Apple's Q&A: Why won't my UIViewController rotate with the device

Now the tricky problem:

If I switch from 2nd VC to the 3rd VC, change the orientation there from portrait to landscape and press the BackButton everything is working (shouldAutorotateToInterfaceOrientation is calling, frame size and origins changing ...). BUT if I do it the other way around, I am in landscape mode, switch from 2nd VC to 3rd VC, rotate to portrait and come back to 2nd VC with BackButton, the status- and controllerBar are at the top but the shouldAutorotateToInterfaceOrientation wasn't called.

Please help me. $h@rky

3

3 Answers

1
votes

Try this, it works for me:

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self shouldAutorotateToInterfaceOrientation:[[UIApplication sharedApplication] statusBarOrientation] ];
}
0
votes

Today I got the idea that solved the problem without knowing the cause. In my third VC I just created a pointer to the 2nd View and called the shouldAutorotateToInterfaceOrientation myself.

But the point is still the same: Why isn't shouldAutorotateToInterfaceOrientation not calling in the described situation?

Kind regards. $h@rky

0
votes

shouldAutorotateToInterfaceOrientation only called when user rotate, so when you from landscape to portrait or otherwise then view controller still landscape, so this solve problem, you have to hack code, it's mean when you push to view controller from landscape to portrait presentViewController example:

ListCurrentViewController *list = [self.storyboard
   instantiateViewControllerWithIdentifier:@"ListCurrentViewController"];
               [self.navigationController presentViewController:list animated:NO completion:Nil];
               [list dismissViewControllerAnimated:NO completion:Nil];
               [self.navigationController pushViewController:list animated:YES];

in ListViewController function called:

(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation // iOS 6 autorotation fix { return UIInterfaceOrientationPortrait; }

and you have to create category for UINavigationController

(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return [self.visibleViewController preferredInterfaceOrientationForPresentation];
}

I hope this solve will help you.