【问题标题】:UIViewController displayed sideways on AirPlay screen when launched from landscape iPad从横向 iPad 启动时,UIViewController 在 AirPlay 屏幕上横向显示
【发布时间】:2023-04-04 08:55:02
【问题描述】:

我正在尝试使用 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 旋转UIWindowUIViewController,这确实修复了方向,但视图不在 AirPlay 显示屏内居中。

编辑

向 Apple 提交了与此相关的问题,rdar://20817189。如果/当我收到回复时,我会更新此内容。

【问题讨论】:

  • 有趣。升级到 IOS 8.3 后,我又开始看到同样的问题。现在我分享你的烦恼。您收到 Apple 票的回复了吗?
  • @ganta 票上什么也没有

标签: ios objective-c ipad airplay


【解决方案1】:

我在文档中找到了这个: 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;
}
}

【讨论】:

  • 谢谢,这确实有效。但是,这似乎有点不直观,我很高兴您能够从文档中破译该注释。
  • 更正:您在 else 语句中使用了错误的枚举。它应该是:UIInterfaceOrientationMaskPortrait。谢谢,这对我也有用。接近我的答案,但谁知道你必须为实际上是横向的方向声明 Portrait :( 如果它离开状态栏并且默认为纵向,这是有道理的
  • - (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)_window 委托方法返回 UIInterfaceOrientationMask 而不是 NSUInteger。
【解决方案2】:

让您的 shouldAutorotateToInterfaceOrientation 方法始终返回 YES 应该会为您解决问题。

【讨论】:

  • 这似乎无法解决问题,电视界面似乎是横向显示的,只是旋转了。
【解决方案3】:

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

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

【讨论】:

    猜你喜欢
    • 2017-07-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多