我尝试使用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
呈现纵向模式。
以纵向连接的屏幕:
屏幕连接横向,内容横向,仅在显示屏的一半上呈现:
我尝试使用UIWindow
轮换UIViewController
和CGAffineTransformMakeRotation
,这确实可以修复方向,但视图不会在AirPlay显示中居中。
修改
提起Apple与此相关的问题,rdar:// 20817189。如果/当我收到回复时,我会更新此信息。
答案 0 :(得分:9)
重要提示:请确保您的应用正确设置状态栏方向。由于外部显示器无法读取主机设备的加速度计以响应方向的变化,因此它依赖于状态栏方向,如应用程序中所设置的那样。
外部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;
}