Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ArtOfWarfare

macrumors G3
Original poster
Nov 26, 2007
9,710
6,304
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:

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?
 
The word "key" means that any events without coordinates will be sent to it, IE key presses or accelerometer events. I don't want those evens to go to the TV screen... Or I do, but I want the iPhone to be where the brains of my app are.

So I don't want "makeKeyAndVisible", I just want "makeVisible", but such a thing doesn't exist, it's just ".hidden = false"

Edit:

I've now experimented with UIScreenMode and have determined that the Apple TV, when hooked up to my TV anyways, only has a single available screen mode. So that's not the issue that's causing the screen to have a black border around it...

I guess the next thing I'll try is experiment with the different Overscan Compensation techniques?

2X Edit:

Tried the various Overscan Compensation techniques, none of them seemed to change anything. Oh well, I just won't worry about the black border. Here's a blog post I found that gives a few pointers on including external screen features in your apps:

http://blog.redfin.com/devblog/2012..._airplay_experience_for_ios_and_apple_tv.html
 
Last edited:
Thanks, i'm waiting for my internet provider to come over and fix internet in my new appartment so I can start experimenting again to, since I don't have a WIFI Connection to hook my devices up to.
I will expirement and let you know, my needs are kind of the same, I don't need any touches going to the second screen, just some output..

*EDIT* Art, you got anywhere?
Sometimes my Apple TV just drops connection all out of a sudden, not sure wether it's my code or not..
Like I said, sometimes it works,s ometimes it doesn't, really really strange.
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.