I know that so many people have asked this question earlier. But I think my situation is different. In my case Xcode 9.2 was already installed and I upgraded macOS from 10.1
Another option that occurred for me. I subclassed UIWindow and called .init(frame: .zero). Changing to .init(frame: UIScreen.main.bounds) fixed it.
.init(frame: .zero)
.init(frame: UIScreen.main.bounds)