0
votes

I have 2 view controllers: ViewControllerA and ViewCotrollerB.

ViewControllerA only support Landscape Left/Right.

These are some methods in ViewControllerA.m:

- (BOOL)shouldAutorotate{
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations{
     return UIInterfaceOrientationMaskLandscape;
}

-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
     return UIInterfaceOrientationLandscapeRight;
}

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{

    [self settingLayoutForOrient:[[UIApplication sharedApplication] statusBarOrientation]];

}

ViewControllerB is displayed when call follow code in ViewControllerA:

ViewControllerB *control = [[ViewControllerB alloc] init];
[self presentViewController:control animated:NO completion:nil];

ViewControllerB support full orientations.

These are some methods in ViewControllerB.m:

- (BOOL)shouldAutorotate{
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations{
     return UIInterfaceOrientationMaskAll;
}

- (void)didRotateFromInterfaceOrientation:  (UIInterfaceOrientation)fromInterfaceOrientation{

[self settingLayoutForOrient:[[UIApplication sharedApplication] statusBarOrientation]];

}

Please help me answer questions in below:

  1. From ViewControllerA and device in Portrait mode, go to ViewControllerB. Why at the first time ViewControllerB apprear, orientation of status always is Landscape left/right and althought device is in portrait mode?

2.How to get exacly orient of status bar in every case (portrait, portraitUpsideDown, FaceUp, FaceDown, landscape left, landscape right) in ViewControllerB at the first time ViewControllerB appear?

Thanks for your help.

1

1 Answers

0
votes

If you are using storyboard you can follow below steps.

As you said you need viewcontrllerA in Landscape Left and right only and viewcontrollerB in all orientation.

For this you can follow below steps

First Create one class of UINavigationController. Name It LandscapeNavigationController

Create another class of UINavigationController. Name It FullNavigationController

Now in LandscapeNavigationController.m file write below code.

- (BOOL)shouldAutorotate
{
    return NO;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
}

Now in FullNavigationController.m file write below code.

- (BOOL)shouldAutorotate
{
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAll;
}

Now Embed your ViewControllerA with NavigationController which will have class LandscapeNavigationController and ViewControllerB with NavigationController which will have class fullNavigationController.

Now set your initial view controller to one of your NavigationController and run your program.