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

发布于 2024-12-22 20:02:17 字数 2377 浏览 4 评论 0原文

我有一个简单的应用程序,仅针对 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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

懒猫 2024-12-29 20:02:17

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文