vendredi 31 juillet 2015

How to fix or disbale orientation of iOS device for few ViewController?

I have an app which is having 9-10 screens.I have embed navigation controller to my view controller.So i have few view controller for which i want set only portrait orientation it means on rotating the device view controller should not rotate to landscape mode.I have tried following solutions?

first:

   NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
   [[UIDevice currentDevice] setValue:value forKey:@"orientation"];

but screen still rotates to landscape.

Second: I created custom view controller class as PortraitViewController & add below code in PortraitViewController.m

@interface PortraitViewController ()

@end

@implementation PortraitViewController

- (BOOL)shouldAutorotate
{

    return YES;
}

- (NSUInteger)supportedInterfaceOrientations
{
    //Here check class name and then return type of orientation
    return UIInterfaceOrientationMaskPortrait;
}

@end

After that i implemented PortraitViewController.h as base class

#import <UIKit/UIKit.h>
#import "PortraitViewController.h"
@interface Login : PortraitViewController
@end

does not work at all still allow view controller to rotate in landscape mode

Is there any other solution i am using iOS 8 & don't want viewcontroller to rotate in landscape mode?

Aucun commentaire:

Enregistrer un commentaire