You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何让iOS App通过AirPlay镜像到Apple TV时不占满整屏?

iOS AirPlay镜像到Apple TV时保持原App屏幕比例(显示黑边)

我开发了一款iOS App,当通过AirPlay将其镜像到Apple TV时,App会占据整个电视屏幕,仿佛UIKit读取了电视的实际尺寸。但这并非我想要的效果——我希望像大多数App那样,按App原屏幕比例适配电视屏幕,显示黑边即可。

  • 补充说明1:仅需原样镜像屏幕,无需展示额外内容。
  • 补充说明2:我仅在App/SceneDelegate中以编程方式设置了委托类(因不想在plist中配置):

AppDelegate 代码

public func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
    // Since we manually create the config instead of reading "DefaultConfiguration" from Info.Plist, we should delete the entry in info.plist.
    let config = UISceneConfiguration(name: nil, sessionRole: connectingSceneSession.role)
    config.delegateClass = Self.self
    config.sceneClass = UIWindowScene.self
    return config
}

SceneDelegate 代码

public func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
    // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
    // If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
    // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
    guard let windowScene = (scene as? UIWindowScene) else { return }
    let window = UIWindow(windowScene: windowScene)
    
    window.rootViewController = rootVC()
    window.makeKeyAndVisible()
    window.overrideUserInterfaceStyle = .light
}

此外,我已移除了plist文件中“application scene manifest”下的类配置项。

内容的提问来源于stack exchange,提问作者OMGPOP

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.23 03:15:14