I'm currently using this hack to get a reference to the underlying NSWindow:
func nsWindow(from window: UIWindow) - AnyObject? {
guard let nsWindows = NSClassFromString("NSApplication")?.value(forKeyPath: "sharedApplication.windows") as? [AnyObject] else { return nil }
for nsWindow in nsWindows {
let uiWindows = nsWindow.value(forKeyPath: "uiWindows") as? [UIWindow] ?? []
if uiWindows.contains(window) { return nsWindow }
}
return nil
}
Then this to set the aspect ratio:
nsw.setValue(CGSize(width: 1.5, height: 1.0), forKey: "aspectRatio")
Which gives the following log output:
WARNING: SPI usage of '-[UINSWindow uiWindows]' is being shimmed. This will break in the future. Please file a radar requesting API for what you are trying to do.
Before filing a feedback request, is there a more robust/approved method of doing this?
1
1
1.4k