Option 1. Have you tried to delay setting the overscanCompensation? Like setting it couple milliseconds later?
Option 2. You might have to adopt the new UISceneDelegate
API. To get it working on my side (without storyboards) this is what I had to do:
In SceneDelegate.swift
:
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let windowScene = (scene as? UIWindowScene) else { return }
let window = UIWindow(windowScene: windowScene)
window.rootViewController = YourViewController(nibName: nil, bundle: nil)
self.window = window
window.makeKeyAndVisible()
}
And if you want to have different UIWindowSceneDelegate
for device screen vs external screen, in your AppDelegate
:
// MARK: - UISceneSession Lifecycle
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
let sceneConfigurationName: String
let delegateClass: AnyClass
if connectingSceneSession.role == UISceneSession.Role.windowExternalDisplay {
sceneConfigurationName = "External Display Configuration"
delegateClass = SceneExternalDelegate.classForCoder()
} else {
sceneConfigurationName = "Default Configuration"
delegateClass = SceneDelegate.classForCoder()
}
let sceneConfiguration = UISceneConfiguration(name: sceneConfigurationName, sessionRole: connectingSceneSession.role)
sceneConfiguration.delegateClass = delegateClass
return sceneConfiguration
}
func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
// Called when the user discards a scene session.
}
Don't forget to set the delegateClass
, that was the missing piece to get the external screen working for me.
And lastly, in your Info.plist
you should register these UISceneConfigurations
(and remove storyboard references if needed):
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
<false/>
<key>UISceneConfigurations</key>
<dict>
<key>UIWindowSceneSessionRoleApplication</key>
<array>
<dict>
<key>UISceneConfigurationName</key>
<string>Default Configuration</string>
<key>UISceneDelegateClassName</key>
<string>$(PRODUCT_MODULE_NAME).SceneDelegate</string>
</dict>
<dict>
<key>UISceneConfigurationName</key>
<string>External Display Configuration</string>
<key>UISceneDelegateClassName</key>
<string>$(PRODUCT_MODULE_NAME).SceneExternalDelegate</string>
</dict>
</array>
</dict>
</dict>
</dict>