2

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

我遵循了所有我能找到的 Apple 示例/文档,但无法解决这个绘图问题。辅助显示器未以正确的方向绘制。

下面是我从一个小型测试应用程序中看到的输出。蓝色框只是一个简单的 UIView,它应该占据整个屏幕,但不是。它似乎在横向中正确绘制,但视图旋转了 90 度。注意蓝色是如何延伸到电视底部的边缘的: 在此处输入图像描述

我想我需要以某种方式强制外部窗口的 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

4

1 回答 1

0

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

于 2012-01-05T13:23:14.037 回答