如何让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
相关产品推荐
相关产品推荐

