iOS - Unexpected orientation displayed after invoking presentViewController from subview
<p>I create 3 controllers:</p>

<ul>
<li>RootViewController: a container view-controller contains a sub-view</li>
<li>SubViewController: a view-controller viewed inside RootViewController via <code>addSubview</code></li>
<li>OverlayViewController: presented by using <code>presentViewController</code> from <code>SubViewController</code></li>
</ul>

<p>When rotating device, then show OverlayViewController, then dismiss it, RootViewController will be displayed in unexpected orientation (180 degrees rotated)</p>

<p><a href="https://youtu.be/qBujC0bTYts" rel="nofollow">https://youtu.be/qBujC0bTYts</a></p>

<p>After one-day doing google and trying many things, I see that if I add a sub view-controller into a view-controller without using <code>addChildViewController</code>, it will cause that issue</p>

<pre><code>class RootViewController: UIViewController {

    var subViewController: SubViewController?
    @IBOutlet weak var subView: UIView!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        self.subViewController =  UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("SubViewController") as? SubViewController
        self.subView.addSubview((self.subViewController?.view)!)
        self.subViewController?.view.frame = self.subView.bounds

        //ADD THIS TO FIX ERROR
        self.addChildViewController(self.subViewController!)
    }
}
</code></pre>

<p>Would you please help me know why, and how to solve without <code>addChildViewController</code>? Many thanks.</p>