user-44651
user-44651

Reputation: 4124

Force Landscape View on one UIViewController only

I have an app that is portait mode only. I only have one View Controller that I need to force into landscape mode (A customer signature view) so there is more room for the customer to sign.

How can I force one ViewController to appear in landscape mode. Leaving the rest in portrait?

I have tried setting the app's General Deployment info to Portrait, Landscape Left

enter image description here

And then using this code on the Signature View

- (BOOL)shouldAutorotate {
    return YES;
}

and returning NO on all other view controllers. But that didn't seem to work.

I also included

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft); 
}

Is this possible?

Upvotes: 3

Views: 2867

Answers (3)

Meet
Meet

Reputation: 1206

Following is the the way its working for me:-

-(UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscapeLeft;
}

and 

- (BOOL)shouldAutorotate {
    return NO;
}

Another way is to define orientation in prepareForSegue and fixed orientation of the required VC and set shouldAutorotate to NO in that VC.

Let me know if mentioned code doesn't work for you.

Upvotes: 0

Palanichamy
Palanichamy

Reputation: 96

Try this code in the Signature View Controller

 - (void)viewDidLoad
{
    [super viewDidLoad];
    [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIInterfaceOrientationLandscapeLeft] forKey:@"orientation"];
}

-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIInterfaceOrientationPortrait] forKey:@"orientation"];
}

Upvotes: 1

JingJingTao
JingJingTao

Reputation: 1790

You're just missing the following code below, if your UIViewController is a rootcontroller of a navigationcontroller you need to put the code in the navigationcontroller. Hope this helps, good luck.

- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
}

Upvotes: 0

Related Questions