从风景iPad发布时,UIViewController在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
并且看起来像肖像模式。
屏幕连接为纵向:
屏幕连接在横向,内容是侧面的,只在一半的显示器上呈现:
我尝试使用CGAffineTransformMakeRotation
旋转UIWindow
和UIViewController
,这确实修复了方向,但视图没有在AirPlay显示内部居中。
编辑
提交与此相关的Apple问题,rdar:// 20817189。 如果/当我收到回复时,我会更新此信息。
我在文档中找到了这个: 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; } }
让您的shouldAutorotateToInterfaceOrientation
方法始终返回YES
应该为您排序。
设置为人像面具的Airplay窗口永远不会旋转。 默认状态栏为纵向,因此旋转值基于此。 这是一个有效的代码示例(假设您在连接时已将Airplay UIWindow存储为AppDelegate上的self.secondWindow)
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { if(window == self.secondWindow){ return UIInterfaceOrientationMaskPortrait; } return UIInterfaceOrientationMaskAll; }