【问题标题】:iOS 5 AirPlay screen not drawing correctly in landscapeiOS 5 AirPlay 屏幕无法以横向正确绘制
【发布时间】:2023-04-05 15:07:01
【问题描述】:

我有一个仅针对 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

【问题讨论】:

  • 您的代码看起来不错...除了您应该先在 loadView 中调用 [super loadView]。
  • 你解决过这个问题吗?我有完全相同的问题。但在 iOS 8 中。
  • @DustinPfannenstiel 我今天遇到了同样的问题,这篇文章是否与您的问题相符? stackoverflow.com/questions/30040055/…

标签: ios ios5 airplay


【解决方案1】:

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

【讨论】:

  • 关于如何在 iOS 8 中执行此操作的任何建议?
猜你喜欢
  • 2023-04-04
  • 2021-05-05
  • 2015-06-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多