I'm trying to create an overlay I can use from any view controller to host preview images for draggable views.
From my AppDelegate.swift
import UIKit
import MaterialComponents
var myOverlayWindow: MDCOverlayWindow?
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
window!.overrideUserInterfaceStyle = .dark
// Override point for customization after application launch.
myOverlayWindow = MDCOverlayWindow.init(windowScene: window!.windowScene!)
return true
}
}
and in another View Controller:
func showOverlay() {
let testView = UIView(frame: CGRect(x: 0, y: 0, width: 500, height: 500))
testView.backgroundColor = .systemRed
myOverlayWindow!.activateOverlay(testView, withLevel: .normal)
print("overlay should show")
}
Why isn't the overlay activating and displaying testView
? Am I instantiating MDCOverlayWindow incorrectly?