如何根据对另一个 UIWindow 的更改来更新 UIWindow?

How to update UIWindow based on changes to another UIWindow?

当我的iPhone/iPad要连接到外部显示器时出现这种情况。

在正常情况下,整个设备的屏幕都会镜像到外部显示器。但是,对于特定的 view/page.

,我需要外部显示器上的屏幕来显示与设备中不同的内容

我在 UIScrollView 中有一个 UIImageView,还有一些相关按钮(下一个、上一个等)作为应用程序特定视图控制器的一部分。我希望外部设备只显示 UIScrollView 中的内容(即不显示按钮)。为此,我似乎必须为外部显示屏创建另一个 UIWindow 实例。

但是,如何使外部显示器中的 UIWindow(及其内容)相应地响应对主 UIWindow(显示在 iPhone/iPad 中的那个)所做的更改。即放大缩小等变化

你可以这样做:

- (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;

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

        // Set up initial content to display...
        secondWindow.rootViewController = [ExternalScreenViewController sharedExternalScreen];

        // Show the window.
        self.secondWindow.hidden = NO;
    }
}

现在您需要做的就是创建 ExternalScreenViewController 并使用填充整个 viewController 的 UIView。最后,您只需将目标的视图设置为等于滚动视图的视图。