Created
December 13, 2012 08:04
-
-
Save zapsleep/4274903 to your computer and use it in GitHub Desktop.
Obtain notifies of connecting and disconnecting screens
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//setting notifiers | |
- (void)setupScreenConnectionNotificationHandlers { | |
NSNotificationCenter* center = [NSNotificationCenter | |
defaultCenter]; | |
[center addObserver:self selector:@selector( | |
handleScreenConnect:) | |
name:UIScreenDidConnectNotification object:nil]; | |
[center addObserver:self selector:@selector( | |
handleScreenDisconnect:) | |
name:UIScreenDidDisconnectNotification object:nil]; | |
} | |
//handling screen connection | |
- (void)handleScreenConnect:(NSNotification*)aNotification | |
{ | |
UIScreen* newScreen = [aNotification object]; | |
CGRect screenBounds = newScreen.bounds; | |
if (!_secondWindow) | |
{ | |
_secondWindow = [[UIWindow alloc] initWithFrame:screenBounds]; | |
_secondWindow.screen = newScreen; | |
// Set the initial UI for the window. | |
[viewController displaySelectionInSecondaryWindow: | |
_secondWindow]; | |
} | |
} | |
//handling screen disconnection | |
- (void)handleScreenDisconnect:(NSNotification*)aNotification | |
{ | |
if (_secondWindow) | |
{ | |
// Hide and then delete the window. | |
_secondWindow.hidden = YES; | |
[_secondWindow release]; | |
_secondWindow = nil; | |
// Update the main screen based on what is showing here. | |
[viewController displaySelectionOnMainScreen]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment