user3711263
user3711263

Reputation: 69

How to avoid autorotation in iOS 8 from Xcode?

I am using Xcode and after updating to iOS 8, the shouldAutorotate function doesn't work. I don't want my viewcontroller to autorotate.

How can I restrict autorotation in iOS 8 from Xcode?

Upvotes: 0

Views: 2824

Answers (2)

G. Hazarath Reddy
G. Hazarath Reddy

Reputation: 57

Add the following code in Navigation controller class


-(BOOL)shouldAutorotate
{

return NO;    
}

-(NSUInteger)supportedInterfaceOrientation

{

    return UIInterfaceOrientationPortrait;

}

Upvotes: 0

Banker Mittal
Banker Mittal

Reputation: 1918

Follow these steps:

  1. First, in info.plist select the orientations which your application supports. Meaning if your application only displays in portrait mode then select portrait as your only setting.

    enter image description here

    If you want to restrict this orientation from appdelegate you can add this code

    - (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
        NSUInteger orientations;
    
        UIViewController* presented = [[[[NavigationManager sharedManager ] navigationController] viewControllers] lastObject];
        orientations = [presented supportedInterfaceOrientations];
    
        return orientations;
    }
    
  2. Make common class for UIViewcontroller and add these methods:

    BaseViewController.h

    @interface BaseViewController : UIViewController{
    }
    

    BaseViewController.m

    - (BOOL)shouldAutorotate
    {
        return NO;
    }
    
    - (NSUInteger)supportedInterfaceOrientations
    {
        return UIInterfaceOrientationMaskPortrait;
    }
    

Upvotes: 4

Related Questions