I just want to get the key window size in a viewcontroller in catalyst environment.Finally I got the window size by "vc.view.window" property.But, it always become nil unexpectedly.When viewDidLoad(), it is nil.When viewWillAppear(), it is nil.Even when a viewcontroller is pop up in a navigation controller. The original viewcontroller's window become nil again.What's the problem.The window size is changable by the user. So, what is the correct way to retrieve the key window size in Catalyst?
Post
Replies
Boosts
Views
Activity
Finally I got the window through the responder chain.func windowBy(vc: UIViewController) -> UIWindow? {
var responder = vc.next
if responder == nil {
responder = vc.navigationController
}
if responder == nil {
responder = vc.presentingViewController
}
while responder != nil {
if responder!.isKind(of: UIWindow.self) {
return responder as? UIWindow
}
responder = responder?.next
}
return nil
}Thank god. It works.
Very cool feature, thanks. I will try it.