iOS AirPlay第二屏幕教程

 三封酒可_894 发布于 2023-02-06 15:06

我正在考虑将AirPlay功能添加到我的一个ViewControllers中.View Controller只显示一个UIWebView.我想要做的是添加一个按钮,将此内容镜像到Apple TV.我知道系统范围的镜像可以完成,但它不会填满整个屏幕,周围都是黑条.我一直在网上搜索,但我发现的大部分内容都是从iOS 5回来并且已经过时了.有人能指出我的教程或插入库的方向会有所帮助吗?我只需要在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");

    }
}

我从这里得到了这一切.但是,这就是它所显示的一切,所以我不确定如何将内容放到该屏幕上.

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有