Skip to content

Instantly share code, notes, and snippets.

@creatd
Created July 5, 2014 09:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save creatd/86214a662903465008a0 to your computer and use it in GitHub Desktop.
Save creatd/86214a662903465008a0 to your computer and use it in GitHub Desktop.
Connecting to external screen (AirPlay)
static FOScreenVC *_vcScreen;
static UIWindow *_externalWindow;
- (void)setupExternalScreen:(UIScreen *)screen {
// Ensure screen is full size
screen.overscanCompensation = UIScreenOverscanCompensationInsetApplicationFrame;
// Create a window for the external screen (if not already)
if (!_externalWindow) {
_externalWindow = [[UIWindow alloc] initWithFrame:screen.bounds];
_externalWindow.windowLevel = UIWindowLevelAlert; // This is a workaround to avoid SVProgressHUD from appearing on external window
_externalWindow.screen = screen;
_externalWindow.hidden = NO;
}
if (!_vcScreen) {
_vcScreen = [FOScreenVC new];
_externalWindow.rootViewController = _vcScreen;
}
}
- (void)destroyExternalScreen {
_externalWindow.screen = nil;
_externalWindow = nil;
_vcScreen = nil;
}
- (void)screenDidConnect:(NSNotification *)notif {
UIScreen *screen = [notif object];
[self setupExternalScreen:screen];
}
- (void)screenDidDisconnect:(NSNotification *)notif {
// Let's reset our window and VC (just in case)
_vcScreen = nil;
_externalWindow = nil;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment