Friday 26 May 2017

Portrait to Landscape Orientation

Portrait to Landscape Orientation 

Step 1 
in AppDelegate.h

#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property(nonatomic) BOOL shouldRotate;
@end

in AppDelegate.m
-(UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
    if (self.shouldRotate)
        return UIInterfaceOrientationMaskAllButUpsideDown;
    else
        return UIInterfaceOrientationMaskPortrait;
}

Step 2 
#import "ViewController.h"
#import "LandscapeView.h"

-(IBAction)onNext:(id)sender
{
    UIStoryboard *story = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    
    LandscapeView *temp = [story instantiateViewControllerWithIdentifier:@"Landscapeid"];
    [self presentViewController:temp animated:YES completion:nil];

}
Step 3

LandscapeView.h

#import <UIKit/UIKit.h>
#import "AppDelegate.h"

@interface LandscapeView : UIViewController
{
    AppDelegate *appDelegate;
}
@end

LandscapeView.m

#import "LandscapeView.h"
@interface LandscapeView ()
@end
@implementation LandscapeView

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    appDelegate = (AppDelegate *) [[UIApplication sharedApplication]delegate];
    [appDelegate setShouldRotate:YES];
}

-(IBAction)onBack:(id)sender{
    [appDelegate setShouldRotate:NO];
    [self dismissViewControllerAnimated:YES completion:nil];
}

-(BOOL)shouldAutorotate{
    return NO;
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
     return (UIInterfaceOrientationMaskLandscapeLeft);
}
@end

Portrait to Landscape Orientation

Portrait to Landscape Orientation  Step 1  in AppDelegate.h #import <UIKit/UIKit.h> @interface AppDelegate : UIResponder ...