#import "ViewController.h" #import "SecondViewController.h" @interface ViewController () @property UIWindow *extWindow; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(screenDidConnect:) name:UIScreenDidConnectNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(screenDidDisconnect:) name:UIScreenDidDisconnectNotification object:nil]; [self performSelector:@selector(checkScreenCount) withObject:nil afterDelay:0]; } -(void) screenDidConnect:(NSNotification*)noti { [self prepareScreen]; } -(void) screenDidDisconnect:(NSNotification*)noti { self.extWindow.hidden = YES; } -(void) checkScreenCount { if ([UIScreen screens].count > 1) [self prepareScreen]; } -(void)prepareScreen { UIScreen* screen = [[UIScreen screens] objectAtIndex:1]; CGRect frame = screen.bounds; self.extWindow = [[UIWindow alloc] initWithFrame:frame]; self.extWindow.screen = screen; SecondViewController* secondViewCtrl = [self.storyboard instantiateViewControllerWithIdentifier:@"secondView"]; self.extWindow.rootViewController = secondViewCtrl; self.extWindow.hidden = NO; } @end