Limiting landscape views in a UITabBarController containing a UINavigationController

I have a tab bar application that contains navigation views in two of its tabs. I would like 1 view in 1 nav controller to be able to view the landscape, but because of the nav bar in the tab bar constraint. Now I need to allow landscape views for every single view in my application in order to make the tilt messages get passed to my application, which I don't want.

I thought, perhaps, on opinions that shouldn't go into the album, that there might be ways: to prevent a change of view, for example. calling setOrientation: UIDeviceOrientationPortrait whenever the device goes landscape or giving the illusion that the view is not changing, for example. presenting a modal portrait view over a rotated view

Anyone have ideas or experiences that they want to share? What's the best approach here? (I don't want to design a landscape view for each view now so that I can display a portrait and landscape view for 1 view)

+2


a source to share


1 answer


I had to deal with the same problem lately and my solution looks like this:

inside the UIViewController of the view you want to rotate , add a notification handler forUIDeviceOrientationDidChangeNotification

-(void)viewDidLoad {


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

      

}

then of course you need to implement your method didRotateFromInterfaceOrientation

.



inside this method you can get the current orientation using

 UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];

      

what i did next was to evaluate the view i want to display based on 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;
    }
}

      

Hope I can help a little.

+2


a source







All Articles