Airplay:外部窗口上的镜像子视图 [英] Airplay: Mirror subview on external window

查看:151
本文介绍了Airplay:外部窗口上的镜像子视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于airplay的设计/建筑问题。
我在AppDelegate中设置了一个外部显示器:

a design / architectural question on airplay. I have setup an external display in the AppDelegate:

UIScreen *externalScreen = UIScreen.screens.lastObject;
self.externalWindow = [[UIWindow alloc] initWithFrame:externalScreenFrame];
self.externalWindow.screen = externalScreen;
self.externalWindow.backgroundColor = [UIColor redColor];

工作正常,电视显示红色的空白屏幕。
现在我有一个带有一堆子视图的ViewController,一个视图应该显示在设备外部屏幕上。如果我在ViewController.m中尝试这个:

Works fine, TV shows an empty screen in red. Now I have a ViewController with a bunch of subviews, and one view should be shown on the device and the external screen. If I try this in ViewController.m:

[_appDelegate.externalWindow addSubview:self.deviceAndTVView];

deviceAndTVView将仅显示在外部屏幕上,而不再显示在设备上。
我需要的是在设备上安装deviceAndTVView,在触摸/用户交互时更新自己,并在外部屏幕上镜像这些更新。

deviceAndTVView will only show on the external screen, not on the device anymore. What I would need is to have deviceAndTVView on the device, updating itself on touches / user interaction, and mirror those updates on the external screen.

这是正确的道路是什么?

Which is the right path to accomplish that?

感谢阅读!
m

Thanks for reading! m

推荐答案

名为AirPlay镜像的技术命名不佳。它实际上以两种模式运行,一种是将整个iOS设备镜像到AirPlay设备,另一种模式是连接镜像AirPlay设备,开发人员可以使用两种UIWindow / UIScreen。

The technology called AirPlay mirroring is poorly named. It actually operates in two modes, one where the entire iOS device is mirrored to the AirPlay device, and in another mode where once the mirroring AirPlay device is connected, the developer has two UIWindow/UIScreen's to work with.

您使用的是后一种模式,通常被称为镜像,但实际上您有一个完全独立的窗口/屏幕需要管理,应该有更好的术语来引用这种模式操作。

You are using the latter mode, which is often referred to as "mirroring", but really you have a completely separate window/screen to manage and there should be better terminology to refer to this mode of operation.

您在上面所描述的内容基本上是移动从设备窗口到AirPlay窗口的UIView,并且它的工作方式完全正常!

What you describe doing above is basically moving a UIView from the device window to the AirPlay window, and it's working exactly as it should!

在这两个窗口上都没有技术方法让你有一个UIView节目的单个实例 - 它将存在于一个窗口中UIView层次结构或另一个,但不能同时进行。换句话说,如果您希望在两个屏幕上显示相同的内容,则需要创建相同UIView的两个实例,并将它们分别添加到两个窗口,然后将它们更新为他们改变了。

There is no technical way for you to have a single instance of a UIView show on both of these windows - it will exist in one UIView hierarchy or the other, but not both at the same time. In other words, if you want the same thing to show on both screens, you need to create two instances of the same UIView, and add them respectively to the two windows, and then update both of them as they change.

虽然这可能不是你所期待的超级镜像,但它可能是一件好事,因为你的UIView在设备上的宽高比可能不同于它在AirPlay设备上。通过显示相同内容的两个不同视图,您可以调整AirPlay视图的大小以充分利用设备的可用分辨率。

While this may not be the super-convienent "mirroring" you were expecting, it's probably be a good thing because your UIView may have different aspect ratio on the device than it does on the AirPlay device. By having two different views, showing the same content, you can adjust the sizing of the AirPlay view to best use of the available resolution of the device.

这篇关于Airplay:外部窗口上的镜像子视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆