从风景iPad启动时,UIViewController在AirPlay屏幕上横向显示

时间:2015-05-04 21:11:19

标签: ios objective-c ipad airplay

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

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

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

为此,我将UIViewController添加到附加的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电视上看到全屏显示。

我发现问题的地方是在iPad处于横向模式时连接AirPlay显示屏。当发生这种情况时,AirPlay显示器会侧向UIViewController呈现纵向模式。

以纵向连接的屏幕:

Launched in portrait, displays ok

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

Launched in landscape, displays sideways

我尝试使用UIWindow轮换UIViewControllerCGAffineTransformMakeRotation,这确实可以修复方向,但视图不会在AirPlay显示中居中。

修改

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

3 个答案:

答案 0 :(得分:9)

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

  

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

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

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

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

答案 1 :(得分:0)

shouldAutorotateToInterfaceOrientation方法始终返回YES应该为您排序。

答案 2 :(得分:0)

设置为人像面具的Airplay窗口永远不会旋转。默认状态栏为纵向,因此旋转值基于此。这是一个有效的代码示例(假设您在连接时已将您的Airplay UIWindow存储为AppDelegate上的self.secondWindow)

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
    if(window == self.secondWindow){
        return UIInterfaceOrientationMaskPortrait;
    }
    return UIInterfaceOrientationMaskAll;
}