2

I have a simple app that is targeting iPad and iOS 5+ only. The app is landscape-only. Now, I want to take advantage of AirPlay mirroring on the iPad 2.

I have followed all of Apple's examples/documentation I can find and can't get past this drawing problem. The secondary display doesn't draw in the correct orientation.

Below is the output I am seeing from a small test app. The blue box is just a simple UIView that should be taking up the entire screen, but is not. It seems to be drawing correctly in landscape, but the view is rotated 90 degrees. Notice how the blue extends past the margin on the bottom of the TV: enter image description here

I think I need to somehow force the ViewController of the external window to correctly draw in landscape, but I don't know the proper way to do this. Any ideas?

Below are the relevant pieces code:

AppDelegate.m:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [[NSNotificationCenter defaultCenter]
        addObserver:self
        selector:@selector(screenDidConnect:)
        name:UIScreenDidConnectNotification
        object:nil];

    [self initScreens];

    return YES;
}

- (void)screenDidConnect:(NSNotification *)note
{
    [self initScreens];
}

- (void)initScreens
{
    if ([[UIScreen screens] count] > 1)
    {
        UIScreen *screen = [[UIScreen screens] lastObject];

        if (!self.secondaryWindow)
        {
            self.secondaryWindow = [[UIWindow alloc] initWithFrame:screen.bounds];
            self.secondaryWindow.screen = screen;
            self.secondaryWindow.hidden = NO;
        }

        if (!self.secondaryViewController)
        {
            self.secondaryViewController = [[CCKSecondaryViewController alloc] init];
        }

        self.secondaryWindow.rootViewController = self.secondaryViewController;
    }
}

CCKSecondaryViewController.m: This is the rootViewController of the external window

- (void)loadView
{
    UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
    view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
    view.backgroundColor = [UIColor blueColor];

    self.view = view;

    UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero];
    label.text = @"Secondary Screen";
    [label sizeToFit];

    [self.view addSubview:label];
    label.center = self.view.center;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}

You can find the sample app here:

http://dl.dropbox.com/u/360556/AirplayTest.zip

pad
  • 41,040
  • 7
  • 92
  • 166
Chandler Kent
  • 363
  • 2
  • 8
  • Your code looks ok... Except you should call [super loadView] in loadView first. – Felix Dec 23 '11 at 22:12
  • Did you ever get this fixed? I'm having the exact same problem. But in iOS 8. – Dustin Pfannenstiel Apr 15 '15 at 18:21
  • @DustinPfannenstiel I ran into the same issue today, does this post match your issue? http://stackoverflow.com/questions/30040055/uiviewcontroller-displayed-sideways-on-airplay-screen-when-launched-from-landsca – francis May 05 '15 at 03:43

1 Answers1

0

It's displaying in portrait on the connected screen. Having your shouldAutorotateToInterfaceOrientation method always return NO should sort it out for you.

Michael Behan
  • 3,433
  • 2
  • 28
  • 38