iOS 5 AirPlay屏幕在横向上无法正确绘制

时间:2011-12-23 21:34:17

标签: ios ios5 airplay

我有一个仅针对iPad和iOS 5+的简单应用。该应用程序仅限景观。现在,我想利用iPad 2上的AirPlay镜像。

我已经关注了我能找到的所有Apple的示例/文档,并且无法解决这个绘图问题。辅助显示屏无法以正确的方向绘制。

以下是我从小型测试应用中看到的输出。蓝盒子只是一个简单的UIView应该占据整个屏幕,但事实并非如此。它似乎在风景中正确绘制,但视图旋转90度。注意蓝色是如何延伸到电视底部边缘的: enter image description here

我想我需要以某种方式强制外部窗口的ViewController在横向上正确绘制,但我不知道这样做的正确方法。有什么想法吗?

以下是相关部分代码:

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: 这是外部窗口的rootViewController

- (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);
}

您可以在此处找到示例应用:

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

1 个答案:

答案 0 :(得分:0)

它在连接的屏幕上以纵向显示。让shouldAutorotateToInterfaceOrientation方法始终返回NO应该为您排序。