iOS AirPlay 第二 screen 教程

标签 ios uiwindow gnu-screen airplay apple-tv

我正在考虑为我的一个 ViewController 添加 AirPlay 功能。 View Controller 只显示一个 UIWebView。我想要做的是添加一个按钮,将此内容镜像到 Apple TV。我知道可以进行系统范围的镜像,但它不会填满整个 screen ,四周都是黑条。我一直在网上搜索,但我发现的大部分内容都是从 iOS 5 回来的,而且已经过时了。有人可以指出我可以提供帮助的教程或嵌入式图书馆的方向吗?我只需要它来镜像一个 View 的内容,以便在 Apple TV 上全屏显示。

到目前为止,这是我所做的,但我相信它只创建了第二个窗口,而没有在上面放置任何东西。

在 AppDelegate 中,我为其创建了一个属性:

@property (nonatomic, retain) UIWindow *secondWindow;

在我运行的 AppDelegate 的 didFinish 方法中:

 NSNotificationCenter *center = [NSNotificationCenter defaultCenter];

    [center addObserver:self selector:@selector(handleScreenDidConnectNotification:)
                   name:UIScreenDidConnectNotification object:nil];
    [center addObserver:self selector:@selector(handleScreenDidDisconnectNotification:)
                   name:UIScreenDidDisconnectNotification object:nil];

然后在 AppDelegate 中我有:

- (void)handleScreenDidConnectNotification:(NSNotification*)aNotification
{
    UIScreen *newScreen = [aNotification object];
    CGRect screenBounds = newScreen.bounds;

    if (!self.secondWindow)
    {
        self.secondWindow = [[UIWindow alloc] initWithFrame:screenBounds];
        self.secondWindow.screen = newScreen;

        // Set the initial UI for the window.
    }
}

- (void)handleScreenDidDisconnectNotification:(NSNotification*)aNotification
{
    if (self.secondWindow)
    {
        // Hide and then delete the window.
        self.secondWindow.hidden = YES;
        self.secondWindow = nil;

    }

}

在我允许在 Apple TV 上镜像 WebView 的 viewController 中,我有:

- (void)checkForExistingScreenAndInitializeIfPresent
{
    if ([[UIScreen screens] count] > 1)
    {
        // Get the screen object that represents the external display.
        UIScreen *secondScreen = [[UIScreen screens] objectAtIndex:1];
        // Get the screen's bounds so that you can create a window of the correct size.
        CGRect screenBounds = secondScreen.bounds;

       appDelegate.secondWindow = [[UIWindow alloc] initWithFrame:screenBounds];
        appDelegate.secondWindow.screen = secondScreen;

        // Set up initial content to display...
        // Show the window.
       appDelegate.secondWindow.hidden = NO;
        NSLog(@"YES");

    }
}

我从 here 得到了所有这些.但是,它只显示了这些内容,所以我不确定如何将内容显示到该 screen 上。

最佳答案

根据您的 WebView 中发生的情况,您要么必须将第二个指向同一页面,要么将现有的移动到新窗口。无论哪种方式,您对待第二个窗口的方式与对待应用程序主窗口的方式几乎相同——向其添加 View ,它们应该显示在第二个显示器上。

关于iOS AirPlay 第二 screen 教程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20929567/

相关文章:

android - 开发人员指南中的 automoveToNext() 方法无法正常工作

ios - 禁用 UITextfield 的键盘

ios - 如何组织 Controller 和 View (iOS)

linux - 向分离 screen 发送命令,这会更改事件窗口

ios - 如何对要添加的单元格进行排序,将其添加到先前单元格的顶部还是先前单元格的底部

ios - 将字典传递给两个数组

ios - 如何快速关闭消息应用程序?

ios - UIKeyboard 弹出时 UIWindow 子类不旋转

python - 使用命令自动加载多个 UNIX screen

java - 从Java执行sh文件