views:

15

answers:

1

I just want to ask if anybody else is also having problems with this;

It used to be that a tabbar app by default didn't allow landscape view unless it was enabled for all views in the app, but one could add

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotateFromInterfaceOrientation) name:@"UIDeviceOrientationDidChangeNotification" object:nil];

to catch the orientation change messages & then react to the messages accordingly.

Lately I've seen that once a landscape view has been shown, every view that does not allow landscape will show that previous landscape view when the phone is tilted.

So, View1 (does not support landscape) tilted phone shows View1 sideways, View2 (supports landscape) tilted phone shows Landscapeview2, now that the landscape view has show once, View1 tilted shows Landscapeview2

I release the viewcontroller after presentModalViewController and dismiss the viewcontroller when the landscape view is no longer needed so it should be gone but on any orientation change after the first display it keeps showing, as if presentModalViewController was being called again.

Any ideas? Anybody else having the same problem? (It never happened with the 3.x OS versions)

A: 

For anybody interested; It seems the landscape enabled view controller was staying as observer for orientation changes even when it was not the active view anymore, basically it was answering to changes for every view.

My solution was to create 2 new BOOL's, 1 called isActiveView and 1 called isShowingLandscape, and used those to ensure that the view controller only responded when it or it's landscape view were being shown.

Relevant code is:

-(void)viewDidAppear:(BOOL)animated
{
  isActiveView = TRUE;
}

-(void)viewDidDisappear:(BOOL)animated
{
  isActiveView = FALSE;
}

-(void)didRotateFromInterfaceOrientation
{
  if ((orientation == UIDeviceOrientationPortrait) && ((isActiveView) || (showingLandscape)))
  {
    [self dismissModalViewControllerAnimated:YES];
    showingLandscape = FALSE;
  }
  else if ((orientation == UIDeviceOrientationLandscapeLeft) && (isActiveView))
  {
    LandscapeViewController *landscapeViewControllerObject = [[LandscapeViewController alloc] initWithNibName:@"LandscapeView" bundle:[NSBundle mainBundle]];
    [self presentModalViewController:landscapeViewControllerObject animated:YES];
    [landscapeViewControllerObject release];
    showingLandscape = TRUE;
  }
  else if ((orientation == UIDeviceOrientationPortraitUpsideDown) && ((isActiveView) || (showingLandscape)))
  {
    [self dismissModalViewControllerAnimated:YES];
    showingLandscape = FALSE;
  }
  else if ((orientation == UIDeviceOrientationLandscapeRight) && (isActiveView))
  {
    LandscapeViewController *landscapeViewControllerObject = [[LandscapeViewController alloc] initWithNibName:@"LandscapeView" bundle:[NSBundle mainBundle]];
    [self presentModalViewController:landscapeViewControllerObject animated:YES];
    [landscapeViewControllerObject release];
    showingLandscape = TRUE;
  }
}

Hope this helps anybody else having the same problems.

Spider-Paddy