I'm just working on my first multi-screen app right now and I was wondering if anyone had any pointers...
Right now I have a simple app whose delegate has a property for a second window, named secondWindow.
The code for handling it looks like this:
I installed it on my iPhone 4S and turned on AirPlay mirroring to my AppleTV and it mostly worked as expected, except there was a black border around the entire white view.
I then tried adding text to the top center of my initial view for SecondStoryboard, but when I ran the app it appeared at the top right of the TV screen instead (with half of the text hanging off into the black border.) I tried changing the text and found that it was centering the text at the edge between the white and black on the right side of the TV screen instead of in the center of the TV screen.
Any idea why that would happen? Has anyone found any tutorials covering using second screens or done it themselves?
Right now I have a simple app whose delegate has a property for a second window, named secondWindow.
The code for handling it looks like this:
Code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
if ([[UIScreen screens] count] > 1) {
[self setupSecondScreen:[[UIScreen screens] objectAtIndex:1]];
}
NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
[center addObserver:self selector:@selector(screenDidConnect:) name:UIScreenDidConnectNotification object:nil];
[center addObserver:self selector:@selector(screenDidDisconnect:) name:UIScreenDidDisconnectNotification object:nil];
[center addObserver:self selector:@selector(screenModeDidChange:) name:UIScreenModeDidChangeNotification object:nil];
[center addObserver:self selector:@selector(screenBrightnessDidChange:) name:UIScreenBrightnessDidChangeNotification object:nil];
return YES;
}
- (void)screenDidConnect:(NSNotification*)notification {
[self setupSecondScreen:[notification object]];
}
- (void)screenDidDisconnect:(NSNotification*)notification {
if (self.secondWindow) {
self.secondWindow.rootViewController = nil;
self.secondWindow.screen = nil;
self.secondWindow = nil;
}
}
- (void)screenModeDidChange:(NSNotification*)notification {
if (self.secondWindow) {
self.secondWindow.frame = ((UIScreen*)[notification object]).bounds;
}
}
- (void)screenBrightnessDidChange:(NSNotification*)notification {
}
- (void)setupSecondScreen:(UIScreen*)screen {
if (!self.secondWindow) {
self.secondWindow = [[UIWindow alloc] initWithFrame:screen.bounds];
self.secondWindow.screen = screen;
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"SecondStoryboard" bundle:nil];
self.secondWindow.rootViewController = [storyboard instantiateInitialViewController];
self.secondWindow.hidden = NO;
}
}
I installed it on my iPhone 4S and turned on AirPlay mirroring to my AppleTV and it mostly worked as expected, except there was a black border around the entire white view.
I then tried adding text to the top center of my initial view for SecondStoryboard, but when I ran the app it appeared at the top right of the TV screen instead (with half of the text hanging off into the black border.) I tried changing the text and found that it was centering the text at the edge between the white and black on the right side of the TV screen instead of in the center of the TV screen.
Any idea why that would happen? Has anyone found any tutorials covering using second screens or done it themselves?