1

I want to have two separate XIBs, one for portrait and one for landscape.

My AppDelegate look that:

#import "AppDelegate.h"
#import "ViewController.h"
@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    UIDevice *device = [UIDevice currentDevice];                    //Get the device object
    [device beginGeneratingDeviceOrientationNotifications];         //Tell it to start monitoring the accelerometer for orientation
    NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];    //Get the notification centre for the app
    [nc addObserver:self                                            //Add yourself as an observer
           selector:@selector(orientationChanged:)
               name:UIDeviceOrientationDidChangeNotification
             object:device];

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
/*

    // Override point for customization after application launch.
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil];
    } else {
        self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPad" bundle:nil];
    }
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
 */
    return YES;
}

- (void)orientationChanged:(NSNotification *)note
{
    UIDeviceOrientation deviceOrientation = [[note object] orientation];
    if(deviceOrientation ==UIInterfaceOrientationPortrait){
            NSLog(@"Changed Orientation To Portrait");
        if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
            self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil];
        } else {
            self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPad" bundle:nil];
        }
        self.window.rootViewController = self.viewController;
        [self.window makeKeyAndVisible];
    }
    if(deviceOrientation ==UIInterfaceOrientationLandscapeLeft || deviceOrientation ==UIInterfaceOrientationLandscapeRight){
        NSLog(@"Changed Orientation To Landscape");
        if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
            self.viewController = [[ViewController alloc] initWithNibName:@"landscape_iphone" bundle:nil];
        } else {
            self.viewController = [[ViewController alloc] initWithNibName:@"landscape_ipad" bundle:nil];
        }
        self.window.rootViewController = self.viewController;
        [self.window makeKeyAndVisible];

    }
}

@end

This code loads another XIB, but everything is NOT IN PLACE and the status bar is not rotated!

carlosfigueira
  • 85,035
  • 14
  • 131
  • 171
pbeo
  • 399
  • 1
  • 4
  • 14
  • Possible duplicate of [Alternative iOS layouts for portrait and landscape using just one .xib file](https://stackoverflow.com/questions/18595561/alternative-ios-layouts-for-portrait-and-landscape-using-just-one-xib-file) – mblakele Dec 10 '18 at 19:54

0 Answers0