2

I am new in iOS and I am facing a problem regarding the rotation. I just need to lock the Single view controller rotation in portrait. I am using a code like this

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:NO];
    [UIView setAnimationsEnabled:NO];
    NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeRight];
    [[UIDevice currentDevice] setValue:value forKey:@"orientation"];
} 

And this work fine in Landscape but not in the portrait.How can I used this for portrait. I have tried portrait method like this.

  1. UIInterfaceOrientationMaskPortrait
  2. UIInterfaceOrientationPortrait
  3. UIInterfaceOrientationPortraitUpsideDown
  4. UIInterfaceOrientationMaskPortraitUpsideDown But none work for me. Thanks in Advance!
Muju
  • 884
  • 20
  • 54

1 Answers1

0

Use this code only Portrait orientation view controller, tested on IOS 9 OR later.

// Lock orientation to Portrait

-(UIInterfaceOrientationMask)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}

-(NSUInteger)navigationControllerSupportedInterfaceOrientations:(UINavigationController *)navigationController {
    return UIInterfaceOrientationMaskPortrait;
}

OR

-(NSUInteger)supportedInterfaceOrientations{
 return UIInterfaceOrientationMaskPortrait;
}

-(BOOL)shouldAutorotate {
 return NO;
}

Check this (iOS 6 shouldAutorotate: is NOT being called) answer

Community
  • 1
  • 1
Himanshu Patel
  • 1,015
  • 8
  • 26