views:

257

answers:

1

I have a tab bar application that contains navigation views in 2 of its tabs. I would like 1 view in the 1 navigation controller to allow landscape view but because of the nav bar in tab bar limitation I now have to allow landscape views for every single view in my app to make the tilt messages get passed to my app which I don't want.

I thought perhaps, on the views which shouldn't go to landscape, that there might be ways to either: prevent the view change e.g. calling setOrientation:UIDeviceOrientationPortrait whenever the device goes landscape or giving the illusion that the view doesn't change e.g. presenting a modal portrait view over the rotated view

Anybody have any ideas or experience that they care to share? What is the best approach here? (I don't want to now have to design a landscape view for every view just to so that I can display a portrait & landscape view for 1 view)

+1  A: 

Hi there

I had to deal with the same problem recently and my solution is as follows:

within the UIViewController of the View that you want to be able to rotate add a Notification Handler for the UIDeviceOrientationDidChangeNotification

-(void)viewDidLoad {


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

}

then of course you need to implement your didRotateFromInterfaceOrientation Method.

within that Method you can get the current orientation using

 UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];

what I did next was evaluation the view i want to display, based on the orientation

switch (orientation) {
    case UIDeviceOrientationLandscapeLeft:
        NSLog(@"UIDeviceOrientationLandscapeLeft");
        [self presentModalViewController:LandscapeView animated:YES];

        break;
    case UIDeviceOrientationLandscapeRight:
        NSLog(@"UIDeviceOrientationLandscapeRight");

        [self presentModalViewController:LandscapeView animated:YES];

        break;
    case UIDeviceOrientationPortraitUpsideDown:
        NSLog(@"UIDeviceOrientationPortraitUpsideDown");
        [LandScapeview dismissModalViewControllerAnimated:YES];

        break;
    case UIDeviceOrientationPortrait:
        NSLog(@"UIDeviceOrientationPortrait");
        [LandscapeView dismissModalViewControllerAnimated:YES];
        break;

    case UIDeviceOrientationFaceUp:
        NSLog(@"UIDeviceOrientationFaceUp");

        break;

    case UIDeviceOrientationFaceDown:
        NSLog(@"UIDeviceOrientationFaceDown");
        break;

    default:
        break;
    }
}

I hope i could help a bit.

samsam
oh and don't forget to remove the notification handler if the view disappears... [[NSNotificationCenter defaultCenter] removeObserver: self name: @"UIDeviceOrientationDidChangeNotification" object: nil];
samsam
Spider-Paddy
yep that is correct. I had the same Problem: 5 Portrait Views (each is "root-view" of a NavigationController and hooked up to the TabBar)... you can leave all of them untouched except for the one that is supposed to change rotation. I implemented a Cover-Flow-View to be displays upon changing the devices rotation , it works just fine.
samsam
Spider-Paddy
I used OpenFlow which i custumized a bit. But I had to remove it from my app shortly afterwards, because Apple was recently granted a Design-Patent on Coverflow. Therfore they could possibly sue you for using OpenFlow in you app (but more likely they just won't approve your app)... anyhow, if you like my anwser please accept it :)
samsam
click the check-thingi to award me points.. need points... to survive... yaaarrrrr
samsam

related questions