(Using answer instead of comment due to lack of reputation, sorry.)
I ran into this issue as well and was trying out e.g. the solution pointed out above: It didn't work for me.
So I created a repository with example code to expose the original poster's problem. There are example applications for these scenarios:
- the Custom View Controller is the window's root view controller,
- the Custom View Controller is a child of a UINavigationController which is the window's root view controller,
- the Custom View Controller is a child of a UITabBarController which is the window's root view controller and
- the Custom View Controller is a child of a UINavigationController which is as child of a UITabBarController which is the window's root view controller.
It turned out that the solution from CEarwood actually works… when the custom view controller is a child of a UINavigationController (cases 2 and 4). Hoewever, it does not work in cases 1 and 3.
I hope this information is useful.