从风景iPad发布时,UIViewController在AirPlay屏幕上横向显示 [英] UIViewController displayed sideways on AirPlay screen when launched from landscape iPad

查看:148
本文介绍了从风景iPad发布时,UIViewController在AirPlay屏幕上横向显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用AirPlay在外部显示器上显示全屏,16:9, UIViewController

I'm attempting to display a full screen, 16:9, UIViewController on an external display using AirPlay.

此处的目标是使用自定义视图控制器替换AirPlay镜像,该控制器将跨越外部屏幕的整个大小。

The goal here is to replace AirPlay mirroring with a custom view controller that will span the full size of the external screen.

当iPad处于纵向模式时,屏幕连接时,一切似乎都很好。当它在横向连接时, UIViewController 在外部显示器上横向显示,只填充屏幕的一半。

Everything seems to work great when the screen connects while the iPad is in portrait mode. When it connects in landscape, the UIViewController shows up sideways on the external display and only fills half the screen.

为此,我将 UIViewController 添加到附加的AirPlay UIScreen

In order to this I'm adding my UIViewController to the attached AirPlay UIScreen.

-(void) screenConnected:(NSNotification * ) notification {

    UIScreen * screen = [notification object]; //this should be the airplay display
    UIWindow * window = [[UIWindow alloc] initWithFrame:screen.bounds];
    [currentWindow setScreen:screen];
    UIViewController * controller = [_delegate createControllerForAirplayDisplay:window];
    [window setHidden:NO];
    [window setRootViewController:controller];

}

这似乎工作正常,我看到全屏显示在iPad和AirPlay电视上。

This seems to work fine, I see a full screen display on the iPad as well as the AirPlay TV.

我发现问题是在iPad处于横向模式时连接AirPlay显示器的问题。当发生这种情况时,AirPlay显示器会侧向呈现 UIViewController ,并且看起来像肖像模式。

Where I'm seeing an issue is when the AirPlay display is connected while the iPad is in landscape mode. When this happens the AirPlay display renders the UIViewController sideways and in what looks like portrait mode.

以纵向连接的屏幕:

屏幕连接横向,内容横向并且仅在显示屏的一半上呈现:

我试图旋转 UIWindow UIViewController 使用 CGAffineTransformMakeRotation ,这确实可以修复方向,但视图不会在AirPlay显示中居中。

I've attempted rotating the UIWindow and UIViewController using CGAffineTransformMakeRotation, this does fix the orientation but the view is not centered inside the AirPlay display.

修改

提交与Apple相关的问题,rdar:// 20817189。如果/当我收到回复,我会更新此信息。

Filed an issue with Apple related to this, rdar://20817189. I will update this if/when I hear back.

推荐答案

我在文档中找到了这个:
https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual /WindowAndScreenGuide/UsingExternalDisplay/UsingExternalDisplay.html

I found this in the documentation: https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/WindowAndScreenGuide/UsingExternalDisplay/UsingExternalDisplay.html


重要提示:请确保您的应用正确设置状态栏方向。由于外部显示器无法读取主机设备的加速度计以响应方向的变化,因此它依赖于状态栏方向,如应用程序中所设置的那样。

Important: Be sure that your app sets the status bar orientation correctly. Because the external display can’t read the host device’s accelerometer to respond to changes in orientation, it relies instead on the status bar orientation, as set in your app.

外部 UIWindow 从当前设备获取方向,在本例中为横向。
因此,当您设置rootViewController的帧时,例如(0,0,1270,840),原点位于电视的右上角。

The external UIWindow take the orientation from current device, in this case landscape orientation. So, when you set the frame of your rootViewController, for example (0, 0, 1270, 840) the origin is on top-right corner of your Tv.

您必须以纵向方式强制 UIWindow
我在 AppDelegate 上使用此代码解决了这个问题:

You have to force UIWindow in portrait orientation. I solved this issue with this code on AppDelegate:

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)_window {
if ([UIScreen mainScreen] == _window.screen || !_window) {
    return UIInterfaceOrientationMaskAll;
}else {
    return UIInterfaceOrientationPortrait;
}
}

这篇关于从风景iPad发布时,UIViewController在AirPlay屏幕上横向显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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