0

I would like to make ViewController A portrait and ViewController B landscape. When it runs, all goes portrait even I set app delegate to change as landscape. Would you please tell what to do exactly? The below is my working ..

ViewController A going to view controller B :

        AppDelegate *appDelegate = (AppDelegate *) [UIApplication sharedApplication].delegate;
        appDelegate.restrictRotation = TRUE;


        MapViewController * sliderVC =      [[MapViewController alloc] init ];

        sliderVC.modalPresentationStyle = UIModalPresentationCurrentContext;
        [self presentViewController:sliderVC animated:NO completion:nil];
        sliderVC.view.backgroundColor =  [UIColor clearColor];

AppDelegate.m

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    if(self.restrictRotation)//set the bool value to view controller which you want to load in landscape
        return UIInterfaceOrientationMaskLandscapeRight;
    else
        return UIInterfaceOrientationMaskPortrait;
}
Mauricio Gracia Gutierrez
  • 10,288
  • 6
  • 68
  • 99
Jeff Bootsholz
  • 2,971
  • 15
  • 70
  • 141

3 Answers3

1

Make sure you are supporting the wanted orientation:

Project > Target > General

enter image description here

0yeoj
  • 4,500
  • 3
  • 23
  • 41
0

You should override the following methods on View Controller B:

func shouldAutorotate() -> Bool
func supportedInterfaceOrientations() -> Int
func preferredInterfaceOrientationForPresentation() -> UIInterfaceOrientation

The method you overrode in the AppDelegate is meant for your entire app.

Reference

Mark
  • 7,167
  • 4
  • 44
  • 68
0

I recommend you taking a look at the related documentation.

Multiple Orientations

Basically this is what you need to do for all the view controllers:

#pragma mark Orientation handling

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);
}

-(BOOL)shouldAutorotate
{
    return YES;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown);
}
Manuel Escrig
  • 2,825
  • 1
  • 27
  • 36
  • I have tried But to no avail . Please see this http://stackoverflow.com/questions/31244891/ios-force-landscape-in-one-viewcontroller – Jeff Bootsholz Jul 08 '15 at 01:34