此处的目标是使用自定义视图控制器替换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
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,1270,840),原点位于电视的右上角.
您必须以纵向方式强制UIWindow.
我在AppDelegate上使用此代码解决了这个问题:
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)_window { if ([UIScreen mainScreen] == _window.screen || !_window) { return UIInterfaceOrientationMaskAll; }else { return UIInterfaceOrientationPortrait; } }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。