使用外部显示器显示独特内容后,如何在 iPad 应用程序上重新启用应用程序镜像?

发布于 2024-11-19 09:16:51 字数 796 浏览 3 评论 0原文

在我的应用程序中,我创建一个辅助窗口并向其添加一个子视图,以便主屏幕(ipad)和外部显示屏显示不同的内容。

我的问题是,当我不再希望显示唯一内容后,如何重新启用默认应用程序镜像?我尝试仅释放我创建的窗口,并尝试设置屏幕mirroredScreen属性,但它是只读的。

以下是在外部显示器上添加独特内容的代码:

if ([[UIScreen screens] count] > 1) {
        //allocate another window
        UIScreen* secondScreen = [[UIScreen screens] objectAtIndex:1];
        CGRect screenBounds = secondScreen.bounds;

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

        shareViewController.view.hidden = NO;

        //add the shareViewController's view to the external display
        shareViewController.view.frame = secondWindow.frame;
        [secondWindow addSubview:shareViewController.view];
        secondWindow.hidden = NO;


    }

In my application, I create a secondary window and add a subview to it, so that the main screen(ipad) and the external display screen show different things.

My question is, after I no longer want unique content shown, how can I re-enable the default app mirroring? I tried just releasing the window I created, and also tried to set the screens mirroredScreen property, but it is readonly.

Here is the code for adding the unique content on external monitor:

if ([[UIScreen screens] count] > 1) {
        //allocate another window
        UIScreen* secondScreen = [[UIScreen screens] objectAtIndex:1];
        CGRect screenBounds = secondScreen.bounds;

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

        shareViewController.view.hidden = NO;

        //add the shareViewController's view to the external display
        shareViewController.view.frame = secondWindow.frame;
        [secondWindow addSubview:shareViewController.view];
        secondWindow.hidden = NO;


    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

眼泪淡了忧伤 2024-11-26 09:16:51

对我来说,简单地将第二个窗口设置为零是行不通的。
以下代码的组合就达到了目的。首先,重置第二个窗口,其次,重新分配主屏幕以使其再次支持触摸。

// Reset the second window
self.secondWindow.frame = CGRectZero;
self.secondWindow.screen = nil;
self.secondWindow = nil;

// Reassign your main screen to make it work with touches again
UIWindow *mainScreen = [[[UIApplication sharedApplication] windows] firstObject];
[mainScreen makeKeyAndVisible];

For me simply setting my second window to nil didn't work.
The combination of the following code did the trick. First, reset the secondWindow, second, reassign your main screen to make it work with touches again.

// Reset the second window
self.secondWindow.frame = CGRectZero;
self.secondWindow.screen = nil;
self.secondWindow = nil;

// Reassign your main screen to make it work with touches again
UIWindow *mainScreen = [[[UIApplication sharedApplication] windows] firstObject];
[mainScreen makeKeyAndVisible];
别念他 2024-11-26 09:16:51

只要把窗户拆掉就可以了。然后镜像再次激活。

secondWindow = nil;

Just remove the window. Then mirroring gets active again.

secondWindow = nil;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文